Class: CapriccIo::Message
- Defined in:
- lib/capriccio/runtime/message.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#cached_value ⇒ Object
Returns the value of attribute cached_value.
-
#line ⇒ Object
Returns the value of attribute line.
-
#name ⇒ Object
Returns the value of attribute name.
-
#next ⇒ Object
Returns the value of attribute next.
Attributes inherited from CObject
Class Method Summary collapse
Instance Method Summary collapse
- #call(receiver, context = receiver, *_args) ⇒ Object
-
#initialize(name, line) ⇒ Message
constructor
A new instance of Message.
- #to_s(level = 0) ⇒ Object (also: #inspect)
Methods inherited from CObject
Constructor Details
#initialize(name, line) ⇒ Message
Returns a new instance of Message.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/capriccio/runtime/message.rb', line 10 def initialize(name, line) @name = name @args = [] @line = line @cached_value = case @name when /^\d+/ Runtime['Number'].clone(@name.to_i) when /^"(.*)"$/ Runtime['String'].clone(Regexp.last_match(1)) end @terminator = %W[. \n].include?(@name) super(Runtime['Message']) end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
8 9 10 |
# File 'lib/capriccio/runtime/message.rb', line 8 def args @args end |
#cached_value ⇒ Object
Returns the value of attribute cached_value.
8 9 10 |
# File 'lib/capriccio/runtime/message.rb', line 8 def cached_value @cached_value end |
#line ⇒ Object
Returns the value of attribute line.
8 9 10 |
# File 'lib/capriccio/runtime/message.rb', line 8 def line @line end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/capriccio/runtime/message.rb', line 8 def name @name end |
#next ⇒ Object
Returns the value of attribute next.
8 9 10 |
# File 'lib/capriccio/runtime/message.rb', line 8 def next @next end |
Class Method Details
Instance Method Details
#call(receiver, context = receiver, *_args) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/capriccio/runtime/message.rb', line 25 def call(receiver, context = receiver, *_args) value = if @terminator context elsif @cached_value @cached_value else receiver[name].call(receiver, context, *@args) end return @next.call(value, context) if @next value rescue CapriccIo::Error => e e. ||= self raise end |
#to_s(level = 0) ⇒ Object Also known as: inspect
42 43 44 45 46 47 48 |
# File 'lib/capriccio/runtime/message.rb', line 42 def to_s(level = 0) s = ' ' * level s << "<Message @name=#{@name}" s << (", @args=#{@args.inspect}") unless @args.empty? s << (", @next=\n#{@next.to_s(level + 1)}") if @next "#{s}>" end |