Sha256: e5845c68678d5f012d606b4fc56e3d1884bc02a88d09a810e8fdb4b26be0d5f2

Contents?: true

Size: 960 Bytes

Versions: 14

Compression:

Stored size: 960 Bytes

Contents

class Module

  private

  # Redirect methods to other methods. This simply
  # defines methods by the name of a hash key which
  # calls the method with the name of the hash's value.
  #
  #   class Example
  #     redirect_method :hi => :hello, :hey => :hello
  #     def hello(name)
  #       puts "Hello, #{name}."
  #     end
  #   end
  #
  #   e = Example.new
  #   e.hello("Bob")    #=> "Hello, Bob."
  #   e.hi("Bob")       #=> "Hello, Bob."
  #   e.hey("Bob")      #=> "Hello, Bob."
  #
  # The above class definition is equivalent to:
  #
  #   class Example
  #     def hi(*args)
  #       hello(*args)
  #     end
  #     def hey(*args)
  #       hello(*args)
  #     end
  #     def hello
  #       puts "Hello"
  #     end
  #   end
  #
  # CREDIT: Trans

  def redirect_method( method_hash )
    method_hash.each do |targ,adv|
      define_method(targ) { |*args| send(adv,*args) }
    end
  end

  alias_method :redirect, :redirect_method

end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
facets-2.8.4 lib/core/facets/module/redirect_method.rb
facets-2.8.3 lib/core/facets/module/redirect_method.rb
facets-2.8.2 lib/core/facets/module/redirect_method.rb
facets-2.8.1 lib/core/facets/module/redirect_method.rb
facets-2.8.0 lib/core/facets/module/redirect_method.rb
facets-2.7.0 lib/core/facets/module/redirect_method.rb
facets-2.6.0 lib/core/facets/module/redirect_method.rb
facets-2.4.4 lib/core/facets/module/redirect_method.rb
facets-2.4.3 lib/core/facets/module/redirect_method.rb
facets-2.5.1 lib/core/facets/module/redirect_method.rb
facets-2.4.5 lib/core/facets/module/redirect_method.rb
facets-2.5.0 lib/core/facets/module/redirect_method.rb
facets-2.5.2 lib/core/facets/module/redirect_method.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/core/facets/module/redirect_method.rb