Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix the #try extension to allow chaining, e.g. foo.try.bar.baz

  • Loading branch information...
commit d2ecedd195373ae9f272195a4674ec78f93fafdd 1 parent 42d95a0
@kballard kballard authored
Showing with 4 additions and 3 deletions.
  1. +1 −1  lib/extensions.rb
  2. +3 −2 spec/extensions_spec.rb
View
2  lib/extensions.rb
@@ -10,7 +10,7 @@ class NilClass
klass.class_eval do
instance_methods.each { |meth| undef_method meth.to_sym unless meth =~ /^__(id|send)__$/ }
def method_missing(*args)
- nil
+ self
end
end
NilProxy = klass.new
View
5 spec/extensions_spec.rb
@@ -17,8 +17,9 @@
end
specify "nil should ignore any calls made past #try" do
- nil.try.size.should == nil
- nil.try.sdlfj.should == nil
+ nil.try.size.should equal(NilClass::NilProxy)
+ nil.try.sdlfj.should equal(NilClass::NilProxy)
+ nil.try.one.two.three.should equal(NilClass::NilProxy)
end
specify "classes should respond just like objects" do
Please sign in to comment.
Something went wrong with that request. Please try again.