Class: Pry::Hackage::ModOpHack
Constant Summary collapse
- PAIR_MATCHES =
{'[' => ']', '{' => '}', '(' => ')', '<' => '>'}
Instance Method Summary collapse
-
#initialize(char, &block) ⇒ ModOpHack
constructor
A new instance of ModOpHack.
- #score(str) ⇒ Object
Methods inherited from Hack
#ignore, #replace, #replace_with, #run
Constructor Details
#initialize(char, &block) ⇒ ModOpHack
Returns a new instance of ModOpHack.
139 140 141 142 143 144 145 |
# File 'lib/pry/hack.rb', line 139 def initialize(char, &block) @CHAR = char @CODE = block define_singleton_method(:capture) do |x| [][x] end end |
Instance Method Details
#score(str) ⇒ Object
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/pry/hack.rb', line 148 def score(str) str.strip! char = Regexp.escape(str[1]) char_to_match = Regexp.escape(PAIR_MATCHES[str[1]]||str[1]) @PATTERN = /^#{@CHAR}(#{char})(.*)(#{char_to_match})$/ scr = super str define_singleton_method(:delimiter) { Struct.new(:open,:close).new(capture(1), capture(3)) } define_singleton_method(:content) { capture(2) } return scr end |