class SmartCase
Constants
- VERSION
Public Class Methods
new(o = nil)
click to toggle source
# File lib/smart_case.rb, line 2 def initialize(o = nil) @o, @when, @then = o, [], [] instance_eval(&Proc.new) if block_given? self end
Public Instance Methods
call(o = nil, multi: nil)
click to toggle source
# File lib/smart_case.rb, line 11 def call(o = nil, multi: nil) raise ArgumentError unless @when.size == @then.size if multi result = @when.zip(@then).map do |w, t| w.call(o || @o) ? t.call(o || @o) : nil end return result else @when.zip(@then).each do |w, t| return t.call(o || @o) if w.call(o || @o) end end return nil end
t(proc = nil)
click to toggle source
# File lib/smart_case.rb, line 9 def t(proc = nil) @then << (proc || Proc.new) end
w(proc = nil)
click to toggle source
# File lib/smart_case.rb, line 8 def w(proc = nil) @when << (proc || Proc.new) end