All Questions

412
votes
12answers
95428 views

What does map(&:name) mean in Ruby?

I found this code in a RailsCast: def tag_names @tag_names || tags.map(&:name).join(' ') end What does the (&:name) in map(&:name) mean?
251
votes
18answers
59153 views

What does ||= (or-equals) mean in Ruby?

What does the following code mean in Ruby? ||= Does it have any meaning or reason for the syntax?
195
votes
11answers
81254 views

Is Ruby pass by reference or by value?

@user.update_languages(params[:language][:language1], params[:language][:language2], params[:language][:language3]) lang_errors = @user.errors logger.de...
790
votes
19answers
339694 views

What is attr_accessor in Ruby?

I am having a hard time understanding attr_accessor in Ruby. Can someone explain this to me?
733
votes
6answers
214256 views

Why is it bad style to `rescue Exception => e` in Ruby?

Ryan Davis’s Ruby QuickRef says (without explanation): Don’t rescue Exception. EVER. or I will stab you. Why not? What’s the right thing to do?
58
votes
3answers
8403 views

Why do Ruby setters need "self." qualification within the class?

Ruby setters—whether created by (c)attr_accessor or manually—seem to be the only methods that need self. qualification when accessed within the class itself. This seems to put Ruby alone the worl...
78
votes
5answers
15445 views

Strange, unexpected behavior (disappearing/changing values) when using Hash default value, e.g. Hash.new([])

Consider this code: h = Hash.new(0) # New hash pairs will by default have 0 as values h[1] += 1 #=> {1=>1} h[2] += 2 #=> {2=>2} That’s all fine, but: h = Hash.new([]) # Empty arr...
273
votes
2answers
76788 views

Ruby ampersand colon shortcut

Possible Duplicate: What does map(&:name) mean in Ruby? In Ruby, I know that if I do: some_objects.each(&:foo) It's the same as some_objects.each { |obj| obj.foo } That is, &a...
257
votes
4answers
64552 views

What is the difference between <%, <%=, <%# and -%> in ERB in Rails?

Can some one please describe the usage of the following characters which is used in ERB file: <% %> <%= %> <% -%> <%# %> what's the usage of each one ?
787
votes
18answers
394095 views

Calling shell commands from Ruby

How do I call shell commands from inside of a Ruby program? How do I then get output from these commands back into Ruby?

Previous Next