Skip to content

Instantly share code, notes, and snippets.

@gja
Created July 7, 2012 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gja/3065544 to your computer and use it in GitHub Desktop.
Save gja/3065544 to your computer and use it in GitHub Desktop.
Ruby Similar Constructs
x = true and false
puts x # print out true
x = true && false
puts x # print out false
render(:page) and return unless some_data.present?
# Identical
if true and false; end
if true && false; end
# Identical
foo = bar or raise "exception"
foo = bar || raise "exception"
# 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
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