Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding conditionals and other issues #30 #29 #28

  • Loading branch information...
commit 596aac5641e3586be9cb6300618395383dcd26a6 1 parent 278651c
@joaomdmoura authored
Showing with 73 additions and 0 deletions.
  1. +73 −0 lib/runtime/bootstrap.rb
View
73 lib/runtime/bootstrap.rb
@@ -39,3 +39,76 @@
@code << arguments.first.ruby_value
Runtime["nil"]
end
+
+Runtime["Number"].runtime_methods["+"] = proc do |receiver, arguments|
+ result = receiver.ruby_value + arguments.first.ruby_value
+ Runtime["Number"].new_with_value(result)
+end
+
+Runtime["Number"].runtime_methods["-"] = proc do |receiver, arguments|
+ result = receiver.ruby_value - arguments.first.ruby_value
+ Runtime["Number"].new_with_value(result)
+end
+
+Runtime["Number"].runtime_methods["/"] = proc do |receiver, arguments|
+ result = receiver.ruby_value / arguments.first.ruby_value
+ Runtime["Number"].new_with_value(result)
+end
+
+Runtime["Number"].runtime_methods["*"] = proc do |receiver, arguments|
+ result = receiver.ruby_value * arguments.first.ruby_value
+ Runtime["Number"].new_with_value(result)
+end
+
+Runtime["Number"].runtime_methods["<"] = proc do |receiver, arguments|
+ if receiver.ruby_value < arguments.first.ruby_value
+ Runtime["true"]
+ else
+ Runtime["false"]
+ end
+end
+
+Runtime["Number"].runtime_methods["<="] = proc do |receiver, arguments|
+ if receiver.ruby_value <= arguments.first.ruby_value
+ Runtime["true"]
+ else
+ Runtime["false"]
+ end
+end
+
+Runtime["Number"].runtime_methods[">"] = proc do |receiver, arguments|
+ if receiver.ruby_value > arguments.first.ruby_value
+ Runtime["true"]
+ else
+ Runtime["false"]
+ end
+end
+
+Runtime["Number"].runtime_methods[">="] = proc do |receiver, arguments|
+ if receiver.ruby_value >= arguments.first.ruby_value
+ Runtime["true"]
+ else
+ Runtime["false"]
+ end
+end
+
+Runtime["Number"].runtime_methods["=="] = proc do |receiver, arguments|
+ if receiver.ruby_value == arguments.first.ruby_value
+ Runtime["true"]
+ else
+ Runtime["false"]
+ end
+end
+
+Runtime["String"].runtime_methods["=="] = proc do |receiver, arguments|
+ if receiver.ruby_value == arguments.first.ruby_value
+ Runtime["true"]
+ else
+ Runtime["false"]
+ end
+end
+
+Runtime["String"].runtime_methods["+"] = proc do |receiver, arguments|
+ result = receiver.ruby_value + arguments.first.ruby_value.to_s
+ Runtime["String"].new_with_value(result)
+end
Please sign in to comment.
Something went wrong with that request. Please try again.