Possible Duplicate:
What is the -> (stab) operator in Ruby?
I am trying to learn Objects on Rails book and find problem to understand what -> operator mean.
The code is:
describe Blog do
subject { Blog.new(->{entries}) }
let(:entries) { [] }
it "has no entries" do
subject.entries.must_be_empty
end
describe "#new_entry" do
let(:new_post) { OpenStruct.new }
before do
subject.post_source = ->{ new_post }
end
it "returns a new post" do
subject.new_post.must_equal new_post
end
end
I spend a lot of time to find it in any docs, but couldn’t
That’s a new syntax for lambda. You can also write it like this:
Here’s how old and new versions look like with parameters (thanks to Michael Kohl for suggestion):