Sha256: 3a5b6d9cba2a31816584fdec86d1206370b0962a6ee1ce6f1548cc7855b7386e

Contents?: true

Size: 633 Bytes

Versions: 1

Compression:

Stored size: 633 Bytes

Contents

module Bogus
  class MethodStringifier

    def stringify(method, body)
      <<-RUBY
      def #{method.name}(#{arguments_as_string(method.parameters)})
        #{body}
      end
      RUBY
    end

    def arguments_as_string(arguments)
      arguments.map{|type, name| argument_to_string(name, type) }.compact.join(', ')
    end

    def argument_to_string(name, type)
      if type == :req
        name
      elsif type == :rest
        "*#{name}"
      elsif type == :block
        "&#{name}"
      elsif type == :opt
        "#{name} = {}"
      else
        raise "unknown argument type: #{type}"
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bogus-0.0.1 lib/bogus/method_stringifier.rb