# Statistics module problem

**URL:** <https://www.ruby-forum.com/t/statistics-module-problem/57017>\
**Category:** Ruby\
**Created:** [April 6, 2006, 4:10pm UTC](https://www.ruby-forum.com/t/statistics-module-problem/57017 "2006-04-06T16:10:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Craig\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3bc359/32.png) [@Craig\_K](https://www.ruby-forum.com/u/Craig_K)\
**Post date:** [April 6, 2006, 4:10pm UTC](https://www.ruby-forum.com/t/statistics-module-problem/57017/1 "2006-04-06T16:10:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Craig\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3bc359/32.png) [@Craig\_K](https://www.ruby-forum.com/u/Craig_K)\
**Post date:** [April 6, 2006, 4:32pm UTC](https://www.ruby-forum.com/t/statistics-module-problem/57017/2 "2006-04-06T16:32:10Z")

</div>

On Apr 6, 2006, at 10:08 AM, Craig K. wrote:

> 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:

The problem is unique to the method ‘class’ because the parser  
confuses the method  
call with the use of ‘class’ as a keyword to start a class/end  
block. The solution  
is to disambiguate the case with an explicit call to self:

```
type.default_block #deprecated
class.default_block #syntax error, parser gets confused
self.class.default_block	# all is well

```

Personally I wish the parser was smarter (but maybe it is a grammar  
problem?) or that  
the method wasn’t called ‘class’ to avoid the ambiguity. For some  
reason I just don’t  
like the extraneous ‘self’.

Gary W.
