Class: Dslh
- Inherits:
-
Object
- Object
- Dslh
- Defined in:
- lib/dslh.rb,
lib/dslh/version.rb
Defined Under Namespace
Classes: Scope
Constant Summary collapse
- VERSION =
'0.1.4'
Class Method Summary collapse
Instance Method Summary collapse
- #eval(expr = nil, &block) ⇒ Object
-
#initialize(options = {}) ⇒ Dslh
constructor
A new instance of Dslh.
Constructor Details
#initialize(options = {}) ⇒ Dslh
Returns a new instance of Dslh.
26 27 28 |
# File 'lib/dslh.rb', line 26 def initialize( = {}) @options = .dup end |
Class Method Details
.eval(expr_or_options = nil, options = nil, &block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dslh.rb', line 4 def self.eval( = nil, = nil, &block) if and not .kind_of?(Hash) raise TypeError, "wrong argument type #{.class} (expected Hash)" end expr = nil ||= {} if case when String expr = when Hash .update() else raise TypeError, "wrong argument type #{.class} (expected String or Hash)" end end self.new().eval(expr, &block) end |
Instance Method Details
#eval(expr = nil, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/dslh.rb', line 30 def eval(expr = nil, &block) retval = {} scope = Scope.new scope.instance_variable_set(:@__options__, @options) scope.instance_variable_set(:@__hash__, retval) if expr eval_args = [expr] [:filename, :lineno].each do |k| eval_args << @options[k] if @options[k] end scope.instance_eval(*eval_args) else scope.instance_eval(&block) end return retval end |