John Merlino wrote in post #1029066:
> client code:
> ruby-1.9.2-p136 :095 > portfolio.each {|n, b| n <=> b }
You obviously aren't quite understanding what block actually are.
> NoMethodError: undefined method `balance' for nil:NilClass
Well yea. The block that gets passed into each was designed to take one
argument.
Each is a block (a.k.a closure, a.k.a lambda function, a.k.a anonymous
function) that has a design similar to any regular method or function,
for example:
def each(arg) do
# method body
end
If you were to pass two arguments to that method you'd have a similar
result:
self.each(a, b)
=> Results in something just as nasty.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment