RubyFlow The Ruby and Rails community linklog

Incisive Ruby Substitutions - The gsub Hash Syntax

How do you perform multiple Ruby substitutions simultaneously?

I stumbled on a problem today - all parentheses in a text file were facing the )wrong direction( due to conversions from an RTL language. But it dawned on me that if I applied one substitution to flip one bracket, it would just get flipped back on the next substitution! Read my solution on the blog post.

Comments

Thanks for being a guinea pig for the new system! :-)

Nitpick: you talk about semantics, not syntax ;-)

Apeiros - Thanks for reading! I was referring to the gsub hash syntax (gsub(pattern, hash) → new_str) - why is that semantics and not syntax?

Yonibot: because the syntax is about the structure of the language, not its meaning/contents. I.e. the syntax says that you write it as obj.method(arg1, arg2). The semantics of a language concern the meaning. i.e. that if obj is a String and method is “gsub”, you can use it with different types of arguments, and in your case, there are two different semantical usages of gsub which are differentiated by the type of the second argument. I think wikipedia’s article about syntax explains it reasonably well: http://en.wikipedia.org/wiki/Syntax_(programming_languages)

Hmm, seems I need to look into why it’s not picking up links automatically in comments. I’m on it! :)

Seems in Markdown you have to surround a URL by angle brackets for the auto linking to work. I might try and work around that, but for now, a test: http://en.wikipedia.org/wiki/Syntax_(programming_languages)

This should now be resolved: http://example.com/

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in