Chain
Expiremental library for safe method chaining.
person = "John Doe" def person.address = "123 West St." person.address.street #=> Error
To avoid the error use chain:
person.chain.address.street.end #=> nil
Or
~ person.chain.address.street #=> nil
Methods
Public Class methods
[ show source ]
# File lib/more/facets/chain.rb, line 21 def initialize(value) @value = value end
Public Instance methods
[ show source ]
# File lib/more/facets/chain.rb, line 43 def end @missing ? nil : @value end
[ show source ]
# File lib/more/facets/chain.rb, line 25 def method_missing(s,*a, &b) if @value.respond_to?(s) @value = @value.__send__(s,*a,&b) else @missing = true end #begin # @value = @value.__send__(s,*a,&b) #rescue NoMethodError # @missing = true #end self end
[ show source ]
# File lib/more/facets/chain.rb, line 47 def ~@ @missing ? nil : @value end