~/dev/opensource/rbx doc$ cat try_static_scope.rb
class StaticScope
def to_s
puts "parent: #{parent}"
end
end
class Fruit
def initialize(name)
@name = name
puts MethodContext.current.method.staticscope.to_s
end
end
pineapple = Fruit.new("pineapple")
~/dev/opensource/rbx doc$ ./shotgun/rubinius try_static_scope.rb
parent:
Attempted to access field of non-reference.
An exception has occurred:
Attempted to access field of non-reference (null pointer) (ArgumentError)
Backtrace:
StaticScope#to_s at try_static_scope.rb:3
StaticScope#to_s at try_static_scope.rb:3
Fruit#initialize at try_static_scope.rb:10
Class#new at kernel/bootstrap/class.rb:16
Object#__script__ at try_static_scope.rb:14
CompiledMethod#as_script at kernel/core/compiled_method.rb:210
Compile.single_load at kernel/core/compile.rb:240
Compile.load_from_extension at kernel/core/compile.rb:312
Object#__script__ at kernel/loader.rb:190