Skip to content

Instantly share code, notes, and snippets.

@msassak
Created December 29, 2010 05:51
Show Gist options
  • Save msassak/758228 to your computer and use it in GitHub Desktop.
Save msassak/758228 to your computer and use it in GitHub Desktop.
$ ruby-1.8.7-p302 method_chain.rb
method_chain.rb:2: syntax error, unexpected '.', expecting $end
.gsub(/f/, "")
^
$ ruby-1.9.2-p0 method_chain.rb
OO
puts "foo".gsub(/o/, "O")
.gsub(/f/, "")
@tschmidt
Copy link

I noticed this as well. The way I was able to make this work regardless of the ruby version is to do the following:

puts "foo".gsub(/o/, 'O').
           gsub(/f/, '')

@msassak
Copy link
Author

msassak commented Dec 29, 2010

I've used the older syntax before, but I hadn't seen anything about the new one. It always bothered me that I had to end the previous line with the dot rather than begin the new one, so I'm happy for the change.

@tschmidt
Copy link

I agree, leaving the dot at the end of the previous line feels awkward especially since I'm used to being able to continue the chain on the next line from javascript development. I'm glad to see the new syntax supported in Ruby 1.9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment