ForwardableX

ForwardableX is a Ruby library to extend forwardable.rb.

Gem Version Build Status Coverage Status Code Climate

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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request