Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby => operator [duplicate]

Tags:

syntax

ruby

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?

like image 255
arinte Avatar asked Mar 03 '09 20:03

arinte


1 Answers

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.

like image 192
Milan Novota Avatar answered Nov 11 '22 00:11

Milan Novota