Class: Ruby::String

Inherits:
DelimitedList show all
Defined in:
lib/ruby/string.rb

Direct Known Subclasses

DynaSymbol, ExecutableString, Heredoc, Regexp

Instance Attribute Summary

Attributes included from Node::Composite

#parent

Instance Method Summary collapse

Methods inherited from DelimitedList

#nodes

Methods inherited from List

#method_missing, #nodes

Methods included from Alternation::List

#<<, #[]=, #pop

Methods included from Conversions::List

#to_array

Methods inherited from Aggregate

#position, #position=, #prolog, #prolog=, #to_ruby

Methods inherited from Node

#<=>, #all_nodes, #column, #length, #nodes, #row

Methods included from Conversions

included, #to_node

Methods included from Node::Traversal

#has_token?, #has_type?, #has_value?, #is_instance_of?, #left_of?, #matches?, #position?, #right_of?, #select

Methods included from Node::Source

#context, #filename, #line, #lines, #src

Methods included from Node::Composite

included, #root, #root?

Constructor Details

#initialize(contents = nil, ldelim = nil, rdelim = nil) ⇒ String

Returns a new instance of String.



8
9
10
# File 'lib/ruby/string.rb', line 8

def initialize(contents = nil, ldelim = nil, rdelim = nil)
  super(contents, ldelim, rdelim)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Ruby::List

Instance Method Details

#dynamic?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/ruby/string.rb', line 16

def dynamic?
  !elements.inject(true) { |result, element| result && element.respond_to?(:value) }
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/ruby/string.rb', line 20

def respond_to?(method)
  return false if method.to_sym == :value && dynamic?
  super
end

#valueObject



12
13
14
# File 'lib/ruby/string.rb', line 12

def value
  map { |content| content.value }.join
end