Project

General

Profile

Bug #8438 ยป flaw_demo.rb

The flaw_demo.rb contains the whole description of the flaw. - martin_vahi (Martin Vahi), 05/23/2013 03:40 PM

 
#!/usr/bin/env ruby


class Flaw_demo
def initialize
end # initialize

def show_that_the_Binding_instances_are_readable
bn_x=binding()
s_x="\nReading from Binding instances works.\n"
eval("puts s_x",bn_x)
end # show_that_the_Binding_instances_are_readable


def show_that_overwriting_of_existing_vars_works_fine
bn_x=binding()
s_x="\nText subject to overwriting."
eval("s_x=\"\\nThe modification of an existing variable succeeded.\"",bn_x)
puts s_x
end # show_that_overwriting_of_existing_vars_works_fine

def the_flaw_is_that_new_variables_can_not_be_created_to_Binding_instances
bn_x=binding()
eval("s_x=\"\\nA value of a newly created variable\"",bn_x)
puts s_x
end # the_flaw_is_that_new_variables_can_not_be_created_to_Binding_instances


def run_demo
show_that_the_Binding_instances_are_readable()
show_that_overwriting_of_existing_vars_works_fine()
the_flaw_is_that_new_variables_can_not_be_created_to_Binding_instances()
end # run_demo

end # class Flaw_demo

Flaw_demo.new.run_demo()

=begin

# The console output:

ts2@taustas8lm2:~/tmp$ ./flaw_demo.rb

Reading from Binding instances works.

The modification of an existing variable succeeded.
./flaw_demo.rb:25:in `the_flaw_is_that_new_variables_can_not_be_created_to_Binding_instances': undefined local variable or method `s_x' for #<Flaw_demo:0x000000014a2620> (NameError)
from ./flaw_demo.rb:32:in `run_demo'
from ./flaw_demo.rb:37:in `<main>'
ts2@taustas8lm2:~/tmp$ ruby -v
ruby 2.0.0p195 (2013-05-14) [x86_64-linux]
ts2@taustas8lm2:~/tmp$ date
Thu May 23 09:22:53 EEST 2013
ts2@taustas8lm2:~/tmp$

=end


    (1-1/1)