arinte arinte - 26 days ago 19
Ruby Question

Ruby => operator

Where can I find an explanation of what the

=>
operator means in Ruby?

For example,

class Acct < ActiveRecord::Base
validates_confirmation_of :password, :email_address, :on => :create
end


what is the
=>
operator doing in this case?

Answer

The symbol "=>" is not an operator. It's just a syntactic means to express that there is a relationship of "key-value" between the other two elements. It's used to define hashes (or associative arrays, as they're called in some other languages, eg. PHP). In this sense, because "=>" it's not an operator, it doesn't do anything (so as symbols "[" and "]" don't do anything when used to define an array). If you are still confused, have a look into the Hash Ruby class and compare it to the Array class.

Comments