What does this do? I find the example here, but other than what it does, what does it mean? I can’t find anything on google because well, I am not sure what ‘=>’ is even called in this context.
More examples here:
http://mechanize.rubyforge.org/mechanize/EXAMPLES_rdoc.html
In
:text => /Log In/, you are passing a hash topage‘slink_withfunction, and the key in the hash is:textand its corresponding value is/Log In/.Basically:
:x => ymeans that:xis a key in a hash that maps to a value ofy.passing hashes to functions like this allows you to have something like (but not exactly) named parameters.
UPDATE:
A symbol of the form
:somethingis called…. a symbol! You can think of them sort of like global string constants (but they’re not quite the same). Now, when you think back to something like:What you’re actually doing is constructing a new hash on the fly. You create a new element in the hash, where the key is a string with the value “action”, and the value of that element is “/account/login.php” (in this case, also a string, but I’m pretty sure you can store other things in hashes besides strings).
…whew! It’s been a while since I’ve worked with Ruby. I hope I got that all correct. 😉
Some good looking pages here (more can be found by searching google for “ruby symbol”)
http://glu.ttono.us/articles/2005/08/19/understanding-ruby-symbols
http://www.troubleshooters.com/codecorn/ruby/symbols.htm#_What_are_symbols