fork download
  1. # your code goes here
  2.  
  3. def foo(var)
  4. test = lambda do |&val|
  5. val.call() + var
  6. end
  7. end
  8.  
  9. l = Proc.new do foo(56).call { foo(123).call() { 456 } } end
  10.  
  11. puts l.call() {55}
  12.  
  13. puts 456 + 123 + 56
  14.  
  15. class Foo
  16. def blocky(val)
  17. method_name = :foo
  18. if self.class.method_defined?(method_name)
  19. prev = self.class.instance_method(method_name).bind(self)
  20. else
  21. prev = lambda do |&block|
  22. puts "prev_block"
  23. block.call()
  24. end
  25. end
  26.  
  27. scopy = lambda do |&block|
  28. puts "scopy"
  29. prev.call() do
  30. puts "scopy block"
  31. block.call() + val
  32. end
  33. end
  34.  
  35. name = "test"
  36. def self.("#{name}".to_sym)
  37. 999
  38. end
  39.  
  40. self.class.define_method(method_name, scopy)
  41. end
  42. end
  43.  
  44. food = Foo.new
  45. food.blocky(6)
  46. food.blocky(9)
  47. puts food.foo() {1}
  48.  
  49. def food.bar
  50. puts 9999
  51. end
  52.  
  53. food.bar()
  54.  
  55. bar = Foo.new
  56. puts bar.foo() {2}
  57. #puts bar.methods
  58.  
  59. puts bar.bar()
Runtime error #stdin #stdout #stderr 0s 6448KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog.rb:36: syntax error, unexpected '('
		def self.("#{name}".to_sym)
		         ^
prog.rb:36: syntax error, unexpected ')', expecting keyword_end
		def self.("#{name}".to_sym)
		                          ^
prog.rb:42: syntax error, unexpected keyword_end, expecting end-of-input