Sha256: 8297978f33aceb68e10f631ee6cd18564f3aa0ea493f5ca7945b1598b19f39b9

Contents?: true

Size: 723 Bytes

Versions: 6

Compression:

Stored size: 723 Bytes

Contents

# Creates aliases of instance methods. Expects a hash of classes/modules mapped to a hash of instance methods and their aliases
# i.e. {"String"=>{'to_s'=>'s'}}.
class Alias::Creators::InstanceMethodCreator < Alias::Creator
  map do |config|
    config.inject([]) {|t,(klass,aliases)|
      t += aliases.map {|k,v| {:class=>klass, :name=>k, :alias=>v} }
    }
  end

  valid :class, :if=>:class
  valid :instance_method, :if=>:instance_method, :with=>[:class, :name]
  valid :alias, :unless=>:instance_method, :with=>[:class, :alias], :optional=>true

  generate do |aliases|
    aliases.map {|e|
      "#{class_or_module(e[:class])} ::#{e[:class]}; alias_method :#{e[:alias]}, :#{e[:name]}; end"
    }.join("\n")
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
cldwalker-alias-0.2.0 lib/alias/creators/instance_method_creator.rb
cldwalker-alias-0.2.1 lib/alias/creators/instance_method_creator.rb
alias-0.2.3 lib/alias/creators/instance_method_creator.rb
alias-0.2.2 lib/alias/creators/instance_method_creator.rb
alias-0.2.0 lib/alias/creators/instance_method_creator.rb
alias-0.2.1 lib/alias/creators/instance_method_creator.rb