forwardable¶
Notes¶
The forwardable library included in Sapphire is a heavily refactored version of the one that ships with MRI.
The SingleForwardable module has been removed entirely since it was rarely used and not very useful. Instead a single, unified interface has been provided. This is in addition to some code cleanup (making it warning free) and documentation improvements.
Synopsis¶
class Foo
extend Forwardable
delegate :length => :@str
delegate [:first, :last] => :@arr
def initialize
@arr = ["foo","bar","baz"]
@str = "hello"
end
end
f = Foo.new
puts f.length # 5, length of @str
puts f.first # "foo", first element of @arr
puts f.last # "baz", last element of @arr
Acknowledgements¶
Florian Groß was a co-author on the new Forwardable module.