S
Sam Larbi
Note: parts of this message were removed by the gateway to make it a legal Usenet post.
I have this code:
require 'test/unit'
require 'leapyear'
class LeapYearTest < Test::Unit::TestCase
def setup
@ly = LeapYear.new
end
def LeapYearTest.generate_tests
filename = "testdata.dat"
file = File.new(filename, "r")
file.each_line do |line|
year, is_leap = line.split;
code = lambda { assert_equal(is_leap.downcase=="true", @ly.isleap?(
year.to_i)) }
define_method("test_isleap_" + year, code)
end
file.close
end
end
What I want to know is why when I use define_method("name") {block;} instead
of define_method("name", lambda{block}) the binding seems to happen later
(after the each_line loop)?
Is there a reason behind that?
Thanks,
Sammy Larbi
I have this code:
require 'test/unit'
require 'leapyear'
class LeapYearTest < Test::Unit::TestCase
def setup
@ly = LeapYear.new
end
def LeapYearTest.generate_tests
filename = "testdata.dat"
file = File.new(filename, "r")
file.each_line do |line|
year, is_leap = line.split;
code = lambda { assert_equal(is_leap.downcase=="true", @ly.isleap?(
year.to_i)) }
define_method("test_isleap_" + year, code)
end
file.close
end
end
What I want to know is why when I use define_method("name") {block;} instead
of define_method("name", lambda{block}) the binding seems to happen later
(after the each_line loop)?
Is there a reason behind that?
Thanks,
Sammy Larbi