Skip to content

Instantly share code, notes, and snippets.

irb(main):001:0> a, b = nil, 2
=> [nil, 2]
irb(main):002:0> b ||= a
=> 2
irb(main):003:0> b
=> 2
irb(main):004:0> a
=> nil
irb(main):005:0> a ||= b
=> 2
irb(main):001:0> a, b = nil, 2
=> [nil, 2]
irb(main):002:0> a &&= b
=> nil
irb(main):003:0> a = 1
=> 1
irb(main):004:0> a &&= b
=> 2
irb(main):005:0> a
=> 2
class Object
def save
rand > 0.5
end
end
array_of_unsaved_active_record_objects = []
1.upto(10) { |i| array_of_unsaved_active_record_objects << i}
def rubyize obj
return obj unless obj.respond_to?( :java_object)
case obj.java_object.java_type
when "[[Ljava.lang.Long;", "[[Ljava.lang.String;", "[Ljava.lang.Long;", "[Ljava.lang.String;"
obj.map {|o| rubyize o}
when "java.lang.Long"
obj.to_i
when "java.lang.String"
obj.to_s
say -v fred "I aint the one, the one to get played like a pooh butt. See Im from the street, so I know what's up. On these silly games thats played by the women. Im only happy when Im going up in them"; say -v bruce "But you know, Im a menace to society. But girls in biker shorts are so fly to me. So I step to em, with aggression. Listen to the kid, and learn a lesson today." say -v alex "See they think we narrow minded. Cause they got a cute face, and big-behinded. So I walk over and say how ya doin? See Im only down for screwin, but you know, Ya gotta play it off cool. Cause if they catch you slippin, youll get schooled. And theyll get you for your money, son. Next thing you know youre gettin their hair and they nails done." ; say - fred "Fool, and theyll let you show em off. But when it comes to sex, they got a bad cough. Or a headache, its all give and no take. Run out of money, and watch your heart break. Theyll drop you like a bad habit. Cause a brother with money yo, they gotta have it."; say -v bruce
>> (Date.today - 1).to_s
=> "2009-02-17"
>> (Date.today-1).to_s
=> "2009-02-17"
>> (Date.today -1).to_s
=> "2009-02-18"
class ActiveRecord::Base
def log_protected_attribute_removal(*attributes)
s = "WARNING: Can't mass-assign these protected attributes: #{attributes.join(', ')}"
if Rails.env.development? || Rails.env.test?
raise s
else
logger.debug s
end
module Bar
def bar; end
end
module Foo
include Bar
def foo; end
end
class FooBar
1)
NoMethodError in 'Address should postal_code have a valid format'
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.length
/usr/local/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/expectations/fail_with.rb:12:in `fail_with'
/usr/local/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/expectations/handler.rb:21:in `handle_matcher'
/usr/local/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/expectations/extensions/kernel.rb:27:in `should'
/usr/local/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/example/subject.rb:80:in `should'
./spec/models/address_spec.rb:20:
module Shoulda # :nodoc:
module ActiveRecord # :nodoc:
module Matchers
# Ensures that the model is not valid if the given attribute is not
# present.
#
# Options:
# * <tt>with_message</tt> - value the test expects to find in
# <tt>errors.on(:attribute)</tt>. <tt>Regexp</tt> or <tt>String</tt>.