Hacker News new | past | comments | ask | show | jobs | submit login

also to access TLDMs ruby gives us Object#method, but it's kind of gross.

  class Foo
    def bar
      p 'baz'
    end
  end

  bar = Foo.new.method(:bar).to_proc

  3.times &bar
This can also be used if you have a function such as puts where the object is passed in so you can do things such as...

  [1,2,3].each(&method(:puts))
  #instead of
  [1,2,3].each {|i| puts i }
but that's ALSO pretty gross, and usually considered poor form.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: