Here’s a code fragment from the statistics module from Ruby Forge.
code begins here
module Math
module Statistics
VERSION = “2001_02_18”
def self.append_features(mod)
unless mod < Enumerable
raise TypeError,
“`#{self}’ can’t be included non Enumerable (#{mod})”
end
def mod.default_block= (blk)
self.const_set(“STAT_BLOCK”, blk)
end
def mod.default_block
defined?(self::STAT_BLOCK) && self::STAT_BLOCK
end
super
end
def default_block
@stat_block || type.default_block ## <—???
end
def default_block=(blk)
@stat_block = blk
End
code ends
When I run the test program, I get the following warning message:
warning: Object#type is deprecated; use Object#class
So I replaced the line that reads “@stat_block || type.default_block”
with
“@stat_block || class.default_block” and ran the same script and now I
get
the following error message:
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require__’:
c:/ruby/lib/ruby/site_ruby/1.8/math/statistics.rb:162: syntax error
(SyntaxError)
@stat_block || class.default_block
^ from
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require’ from statistics-demo.rb:1
Please help me understand what “type.default_block” does?
Thank you,
–Craig