Class: Mplex
- Inherits:
-
Object
- Object
- Mplex
- Defined in:
- lib/mplex.rb
Overview
Mplex: Extended Metaprogramming Library
Copyright © 2009-2011 FURUHASHI Sadayuki
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Instance Attribute Summary collapse
-
#script ⇒ Object
readonly
Returns the value of attribute script.
Class Method Summary collapse
- .file(fname, context = nil) ⇒ Object
- .result(src, context = nil, fname = "(mplex)", output = "") ⇒ Object
- .script(src) ⇒ Object
- .write(fname, outfname, context = nil) ⇒ Object
Instance Method Summary collapse
-
#initialize(src, fname = "(mplex)") ⇒ Mplex
constructor
A new instance of Mplex.
- #result(context = nil, output = "") ⇒ Object
Constructor Details
#initialize(src, fname = "(mplex)") ⇒ Mplex
Returns a new instance of Mplex.
26 27 28 29 30 |
# File 'lib/mplex.rb', line 26 def initialize(src, fname = "(mplex)") @script = self.class.compile(src) b = nil; Object.new.instance_eval { b = binding } @proc = eval("Proc.new{#{@script}}", b, fname) end |
Instance Attribute Details
#script ⇒ Object (readonly)
Returns the value of attribute script.
31 32 33 |
# File 'lib/mplex.rb', line 31 def script @script end |
Class Method Details
.file(fname, context = nil) ⇒ Object
45 46 47 |
# File 'lib/mplex.rb', line 45 def self.file(fname, context = nil) self.result(File.read(fname), context, fname) end |
.result(src, context = nil, fname = "(mplex)", output = "") ⇒ Object
39 40 41 42 43 |
# File 'lib/mplex.rb', line 39 def self.result(src, context = nil, fname = "(mplex)", output = "") with_context(context, output) {|ctx| ctx.instance_eval(compile(src), fname) } end |
.script(src) ⇒ Object
55 56 57 |
# File 'lib/mplex.rb', line 55 def self.script(src) compile(src) end |
.write(fname, outfname, context = nil) ⇒ Object
49 50 51 52 53 |
# File 'lib/mplex.rb', line 49 def self.write(fname, outfname, context = nil) out = self.result(File.read(fname), context, fname) File.open(outfname, "w") {|f| f.write(out) } out end |
Instance Method Details
#result(context = nil, output = "") ⇒ Object
33 34 35 36 37 |
# File 'lib/mplex.rb', line 33 def result(context = nil, output = "") self.class.with_context(context, output) {|ctx| ctx.instance_eval(&@proc) } end |