Method: Protocol::Message#to_ruby

Defined in:
lib/protocol/message.rb

#to_ruby(result = '') ⇒ Object

Concatenates a method signature as ruby code to the result string and returns it.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/protocol/message.rb', line 57

def to_ruby(result = '')
  if arity
    result << "  def #{name}("
    args = if arity >= 0
      (1..arity).map { |i| "x#{i}" }
    else
      (1..~arity).map { |i| "x#{i}" } << '*rest'
    end
    if block_expected?
      args << '&block'
    end
    result << args * ', '
    result << ") end\n"
  else
    result << "  understand :#{name}\n"
  end
end