class Interscript::Node::Item
Attributes
item[RW]
Public Class Methods
new(item)
click to toggle source
# File lib/interscript/node/item.rb, line 3 def initialize item raise NotImplementedError, "You can't construct a Node::Item directly" end
try_convert(i)
click to toggle source
# File lib/interscript/node/item.rb, line 43 def self.try_convert(i) i = Interscript::Node::Item::String.new(i) if i.class == ::String raise TypeError, "Wrong type #{i.class}, expected I::Node::Item" unless Interscript::Node::Item === i i end
Public Instance Methods
+(other)
click to toggle source
# File lib/interscript/node/item.rb, line 7 def + other this = self this = this.children if Interscript::Node::Item::Group === this other = other.children if Interscript::Node::Item::Group === other this = Array(this) other = Array(other) this = this.map { |i| Interscript::Node::Item.try_convert(i) } other = other.map { |i| Interscript::Node::Item.try_convert(i) } middle = [] if Interscript::Node::Item::String === this.last && Interscript::Node::Item::String === other.first middle = [this.last + other.first] this = this[0..-2] other = this[1..-1] end g = Interscript::Node::Item::Group.new(*this, *middle, *other) g.verify! g end
==(other)
click to toggle source
Calls superclass method
Interscript::Node#==
# File lib/interscript/node/item.rb, line 39 def ==(other) super end
to_hash()
click to toggle source
# File lib/interscript/node/item.rb, line 34 def to_hash { :class => self.class.to_s, :item => self.item } end