Created
July 7, 2012 08:54
-
-
Save gja/3065544 to your computer and use it in GitHub Desktop.
Ruby Similar Constructs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = true and false | |
puts x # print out true | |
x = true && false | |
puts x # print out false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
render(:page) and return unless some_data.present? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Identical | |
if true and false; end | |
if true && false; end | |
# Identical | |
foo = bar or raise "exception" | |
foo = bar || raise "exception" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Equivalent to puts( (1..10).map { |i| i*2 } ) | |
puts (1..10).map { |i| i*2 } | |
# Equivalent to puts( (1..10).map ) { |i| i*2 } | |
> puts (1..10).map do |i| i*2 end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeModel < ActiveRecord::Base | |
scope :for_user, lambda do |user_id| | |
# Some logic here | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment