ForwardableX
ForwardableX is a Ruby library to extend forwardable.rb.
Installation
gem install forwardablex
Usage
Forward to Instance Variable
Receiver = Struct(:m)
class Forwarder
forward :@receiver, :m
def initialize
@recevier = Receiver.new("forwarded")
end
end
Forwarder.new.m #=> "forwarded"
Forward to Proc Receiver
class Forwarder
forward lambda{Struct(:m).new("forwarded")}, :m
end
Forwarder.new.m #=> "forwarded"
Forward to Instance
Receiver = Struct(:m)
class Forwarder
forward Receiver.new("forwarded"), :m
end
Forwarder.new.m #=> "forwarded"
Class Method Accessor
class Forwarder
class << self
def m
"forwarded"
end
end
forward :class, :m
end
Forwarder.new.m #=> "forwarded"
Table Accessor
class Forwarder
forward_as_key :@table, :key
def initialize
@table = {:key => "forwarded"}
end
end
Forwarder.new.key #=> "forwarded"
Identity
class Forwarder
foward :identity, :self
end
Forwarder.new {|x| x == x.self} #=> true
Documentation
Licence
ForwardableX is free software distributed under MIT licence.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request