module MultidispatchDSL::Generator

Public Instance Methods

declaration_from_args(args) click to toggle source
# File lib/multidispatch_dsl/generator.rb, line 17
def declaration_from_args(args)
  list = args.join(', ') { |item| item.class.to_s }
  "(#{ list })"
end
method_name_from_args(base, args) click to toggle source
# File lib/multidispatch_dsl/generator.rb, line 13
def method_name_from_args(base, args)
  method_name_from_declaration(base, args.map(&:class))
end
method_name_from_declaration(base, declaration) click to toggle source
# File lib/multidispatch_dsl/generator.rb, line 4
def method_name_from_declaration(base, declaration)
  if declaration.empty?
    "#{ base }_empty"
  else
    prefix = declaration.map { |klass| underscore(klass) }.join('_')
    "#{ base }_#{ prefix }"
  end
end
underscore(klass) click to toggle source

source code was taken from activesupport library

# File lib/multidispatch_dsl/generator.rb, line 23
def underscore(klass)
  word = klass.to_s.dup
  word.gsub!(/::/, '_')
  word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
  word.tr!("-", "_")
  word.downcase!
  word
end