Class: Rewrite::ByExample::SymbolEntity

Inherits:
EntityMatcher show all
Defined in:
lib/rewrite/by_example/symbol_entity.rb

Overview

Matches a specific symbol: SymbolEntity.new(:foo) matches :foo.

Note that this is not the same thing as matching the use of a symbol in Ruby code, because a literal symbol in Ruby is actually represented as:

s(:lit, :foo)

Instance Attribute Summary collapse

Attributes inherited from EntityMatcher

#predicate

Instance Method Summary collapse

Methods inherited from EntityMatcher

#after_unfold, #such_that!

Constructor Details

#initialize(symbol) ⇒ SymbolEntity

Returns a new instance of SymbolEntity.



17
18
19
# File 'lib/rewrite/by_example/symbol_entity.rb', line 17

def initialize(symbol)
  self.symbol = symbol
end

Instance Attribute Details

#symbolObject

Returns the value of attribute symbol.



15
16
17
# File 'lib/rewrite/by_example/symbol_entity.rb', line 15

def symbol
  @symbol
end

Instance Method Details

#fold(enum_of_bindings) ⇒ Object



25
26
27
# File 'lib/rewrite/by_example/symbol_entity.rb', line 25

def fold (enum_of_bindings)
  self.symbol
end

#to_sObject



29
30
31
# File 'lib/rewrite/by_example/symbol_entity.rb', line 29

def to_s
  ":#{self.symbol.to_s}"
end

#unfold(sexp) ⇒ Object



21
22
23
# File 'lib/rewrite/by_example/symbol_entity.rb', line 21

def unfold (sexp)
  {} if self.symbol == sexp
end