Module: Pyper
- Included in:
- Array, Enumerable, Hash, Range, String
- Defined in:
- lib/pyper.rb,
lib/pyper/version.rb
Overview
Pyper is an extension of the Lispy car/cdr idea.
Defined Under Namespace
Modules: ControlCharacters Classes: PostfixMachine
Constant Summary collapse
- VERSION =
"2.0.0"- DEBUG =
debug level
0
Instance Method Summary collapse
-
#caar ⇒ Object
In their basic form, they are only marginally useful.
- #cadr ⇒ Object
-
#car ⇒ Object
Everybody knows Lispy functions #car, #cdr.
- #cdar ⇒ Object
- #cddr ⇒ Object
-
#cdr ⇒ Object
d: all except first.
-
#method_missing(symbol, *args, &block) ⇒ Object
Reacts to the method symbols delimited with Pyper control characters (τ, π, and χ), compiles them into appropriate methods, and calls them.
-
#respond_to_missing?(symbol, include_private = false) ⇒ Boolean
Respond-to method matching to Pyper#method_missing.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
Reacts to the method symbols delimited with Pyper control characters (τ, π, and χ), compiles them into appropriate methods, and calls them.
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/pyper.rb', line 150 def method_missing( symbol, *args, &block ) str = symbol.to_s super if str.starts_with? 'to_' # quick exclude of "to_something" methods puts "received msg #{str}" if Pyper::DEBUG > 1 case str when /^τ(.+)τ$/ then pyper_mm( symbol, $1, op: 1, ret: 1 ) when /^π(.+)τ$/ then pyper_mm( symbol, $1, op: 2, ret: 1 ) when /^χ(.+)τ$/ then pyper_mm( symbol, $1, op: -2, ret: 1 ) when /^τ(.+)π$/ then pyper_mm( symbol, $1, op: 1, ret: 2 ) when /^π(.+)π$/ then pyper_mm( symbol, $1, op: 2, ret: 2 ) when /^χ(.+)π$/ then pyper_mm( symbol, $1, op: -2, ret: 2 ) when /^τ(.+)χ$/ then pyper_mm( symbol, $1, op: 1, ret: -2 ) when /^π(.+)χ$/ then pyper_mm( symbol, $1, op: 2, ret: -2 ) when /^χ(.+)χ$/ then pyper_mm( symbol, $1, op: -2, ret: -2 ) else super end send symbol, *args, &block # call it right away end |
Instance Method Details
#caar ⇒ Object
In their basic form, they are only marginally useful. Their popularity stems from their compositions:
17 |
# File 'lib/pyper.rb', line 17 def caar; first.first end |
#cadr ⇒ Object
19 |
# File 'lib/pyper.rb', line 19 def cadr; drop(1).first end |
#car ⇒ Object
Everybody knows Lispy functions #car, #cdr. In Ruby, these functions can be defined for example as:
12 |
# File 'lib/pyper.rb', line 12 def car; first end |
#cdar ⇒ Object
18 |
# File 'lib/pyper.rb', line 18 def cdar; first.drop 1 end |
#cddr ⇒ Object
20 |
# File 'lib/pyper.rb', line 20 def cddr; drop(1).drop(1) end |
#respond_to_missing?(symbol, include_private = false) ⇒ Boolean
Respond-to method matching to Pyper#method_missing.
170 171 172 173 174 175 176 177 178 |
# File 'lib/pyper.rb', line 170 def respond_to_missing?( symbol, include_private = false ) str = symbol.to_s super if str.starts_with? 'to_' case str when /^τ(\w+)τ$/, /^π(\w+)τ$/, /^χ(\w+)τ$/, /^τ(\w+)π$/, /^π(\w+)π$/, /^χ(\w+)π$/, /^τ(\w+)χ$/, /^π(\w+)χ$/, /^χ(\w+)χ$/ then true else super end end |