lib/rouge/token.rb in rouge-0.0.2 vs lib/rouge/token.rb in rouge-0.0.3

- old
+ new

@@ -1,10 +1,11 @@ module Rouge class Token attr_reader :name attr_reader :parent attr_accessor :shortname + alias to_s name def make_single(name) name = name.to_s new_name = [self.name, name].compact.join('.') @@ -38,10 +39,19 @@ def sub_tokens @sub_tokens ||= {} end + def ancestors(&b) + return enum_for(:ancestors) unless block_given? + + if parent + yield self + parent.ancestors(&b) + end + end + def ===(other) immediate = if self.class == other.class self == other else self.name == other @@ -60,19 +70,21 @@ def base @base ||= new end def get(name) + return name if name.is_a? Token + base[name] end + alias [] get + def token(name, shortname) tok = get(name) tok.shortname = shortname tok end - - alias [] get def each_token(&b) recurse = proc do |token| b.call(token) token.sub_tokens.each_value(&recurse)