Class: Expressive::TopLevel
Instance Method Summary collapse
-
#initialize ⇒ TopLevel
constructor
A new instance of TopLevel.
- #to_hash ⇒ Object
Methods inherited from Scope
#[], #[]=, #define, #merge, #override_scope, #retrieve_scope, #syntax
Constructor Details
#initialize ⇒ TopLevel
Returns a new instance of TopLevel.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/scope.rb', line 66 def initialize super syntax('set') do |scope, cells| scope[cells.first.text_value] = cells[1].eval(scope) end syntax('post') do |scope, cells| perform_webhook(:post, scope, cells) end syntax('put') do |scope, cells| perform_webhook(:put, scope, cells) end syntax('get') do |scope, cells| perform_webhook(:get, scope, cells) end define('+') {|a,b| a.to_f + b.to_f } define('-') {|a,b| a.to_f - b.to_f } define('*') {|a,b| a.to_f * b.to_f } define('/') {|a,b| a.to_f / b.to_f } define('=') {|a,b| a == b } define('>') {|a,b| a.to_f > b.to_f } define('<') {|a,b| a.to_f < b.to_f } define('>=') {|a,b| a.to_f >= b.to_f } define('<=') {|a,b| a.to_f <= b.to_f } define('and') {|a,b| !!a && !!b } define('or') {|a,b| !!a || !!b } define('sum') { |*args| args.flatten.map(&:to_f).reduce(:+) } define('if') { |*args| args.compact!; args[0] ? args[1] : args[2] } end |
Instance Method Details
#to_hash ⇒ Object
100 101 102 103 |
# File 'lib/scope.rb', line 100 def to_hash h = self.retrieve_scope.dup h.delete_if{|k, v| v.kind_of?(Expressive::Function)} end |