|
|
|
|
|
by b6fan
4598 days ago
|
|
The Ruby examples are unfair. Ruby intentionally makes parenthesis optional. So `do_something` is `do_something()`. For the first example, - method_as_fun = o.my-method
- method_as_fun(5) # not reached
+ method_as_fun = o.method(:my_method)
+ method_as_fun.call(5) # or method_as_fun[5]
And for the lexical scope thing, def f(x)
g = ->y {x + y}
g[2]
end
f(2)
Or, explicitly use class variables, def f(x)
@x = x
def g(y); @x + y; end
g(2)
end
f(2)
|
|