class CurryMethod
def sum(a, b)
a + b
end
end
sum_method = CurryMethod.new.method(:sum)
p(sum_method.to_proc)
sum_method.to_proc.call(1, 2)
#<Proc:0x0000558c0632b080 (lambda)>
3
(0..10).map(&(2.method(:*).to_proc))
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
p sum_method.curry
p sum_method.curry.call(1, 2)
p sum_method.curry.call(1)
sum_method.curry.call(1).call(2)
#<Proc:0x0000558c0693e4e0 (lambda)> 3 #<Proc:0x0000558c06927308 (lambda)>
3
class Foo
if ::Object.method(:const_defined?).arity == 1
def self.const_defined_in?(modul, constant)
modul.const_defined?(constant)
end
else
def self.const_defined_in?(modul, constant)
modul.const_defined?(modul, false)
end
end
end
:const_defined_in?
class Bar
def initilize(src, trim_mode, percent)
super
@trim_mode = trim_mode
@percent = percent
case @trim_mode
when '>'
@scan_line = self.method(:trim_line1)
when '<>'
@scan_line = self.method(:trim_line2)
when '-'
@scan_line = self.method(:explicit_trim_line)
else
@scan_line = self.method(:scan_line)
end
end
end
:initilize