Snippets: Ruby Operators

August 10, 2007 @ 07:47 PM | posted by carmelyne

(last updated: 08.10.07)

High to low precedence of Ruby operators

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
::
[]
**
-(unary) +(unary) ! ~
*  /  %
+  -
<<  >>
&
|  ^
>  >=  <  <=
<=> == === != =~ !~
&&
||
.. ...
= += -=...
not
and or

Source:
http://migo.sixbit.org/papers/Introduction_to_Ruby/slide-21.html
http://www.meshplex.org/wiki/Ruby/Variables_Datatypes_Operators4

Rule Of Thumb:
Use logical operator for logical statements use logical composition sparingly.

[ Last updated: August 10, 2007 @ 07:48 PM ]

Sorry, comments are closed for this article.

Snippets of 06/24/07

Rails 'A'..'Z' Paginate

1
2
3
4
5
6
7
8
9
10
11
# Starts with 'A'..'Z' Paginate / model
def self.sort(sort)
  if sort
    find(:all, :conditions => ['name LIKE ?', "#{sort}%"])
  else
    find(:all, :order => 'name')
  end  
end

# index action / controller
@models = Model.sort(params[:sort]) 

Recent Posts...

RailsConf 2006
I heart devChix