Class: Dslh
- Inherits:
-
Object
- Object
- Dslh
- Defined in:
- lib/dslh.rb,
lib/dslh/version.rb
Defined Under Namespace
Classes: Scope
Constant Summary collapse
- INDENT_SPACES =
' '- VERSION =
'0.1.8'
Class Method Summary collapse
- .deval(hash, options = {}, &block) ⇒ Object
- .eval(expr_or_options = nil, options = nil, &block) ⇒ Object
Instance Method Summary collapse
- #deval(hash) ⇒ Object
- #eval(expr = nil, &block) ⇒ Object
-
#initialize(options = {}) ⇒ Dslh
constructor
of class methods.
Constructor Details
#initialize(options = {}) ⇒ Dslh
of class methods
40 41 42 |
# File 'lib/dslh.rb', line 40 def initialize( = {}) = .dup end |
Class Method Details
.deval(hash, options = {}, &block) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/dslh.rb', line 31 def deval(hash, = {}, &block) if [hash, ].all? {|i| not i.kind_of?(Hash) } raise TypeError, "wrong argument type #{options.class} (expected Hash)" end self.new().deval(hash, &block) end |
.eval(expr_or_options = nil, options = nil, &block) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dslh.rb', line 9 def eval( = nil, = nil, &block) if and not .kind_of?(Hash) raise TypeError, "wrong argument type #{options.class} (expected Hash)" end expr = nil ||= {} if case when String expr = when Hash .update() else raise TypeError, "wrong argument type #{expr_or_options.class} (expected String or Hash)" end end self.new().eval(expr, &block) end |
Instance Method Details
#deval(hash) ⇒ Object
66 67 68 69 70 |
# File 'lib/dslh.rb', line 66 def deval(hash) buf = StringIO.new deval0(hash, 0, buf) buf.string end |
#eval(expr = nil, &block) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/dslh.rb', line 44 def eval(expr = nil, &block) retval = {} scope = Scope.new scope.instance_variable_set(:@__options__, ) scope.instance_variable_set(:@__hash__, retval) [:scope_hook].call(scope) if [:scope_hook] if expr eval_args = [expr] [:filename, :lineno].each do |k| eval_args << [k] if [k] end scope.instance_eval(*eval_args) else scope.instance_eval(&block) end return retval end |