at the toplevel to add sin, cos, etc. to Object class.
It already does. They are there you just can't access them b/c they're
private.
Object.cos(1)
NoMethodError: undefined method `cos' for Object:Class
from (irb):1
irb(main):002:0> include Math
=> Object
irb(main):003:0> Object.cos(1)
NoMethodError: private method `cos' called for Object:Class
from (irb):3
irb(main):004:0> class << Object
irb(main):005:1> public :cos
irb(main):006:1> end
=> #<Class:Object>
irb(main):007:0> Object.cos(1)
=> 0.54030230586814
Interesting. Although David has taken this to mean a merger of Classes
and Modules, that's not necessarily the case. It simply indicates a
different treatment of said module. It would be as if a method other
than #include were used.
module Z
def method; end
end
class A
integrate Z
end
That really does seem like a win-win solution for all.
Speaking of "<<", what about making more use of that piece of syntax?
For example:
class ConcreteThing << Module
end
I don't think that would be precisely "unifying" modules and classes.
I feel pretty comfortable with Ruby these days, and I feel like my
code is highly Ruby-like.
On the other hand, I occasionally miss interfaces and abstract classes
for readability reasons.
···
On 3/21/06, Trans <transfire@gmail.com> wrote:
> Thanks, David. I don't want to make
>
> include Math
>
> at the toplevel to add sin, cos, etc. to Object class.
It already does. They are there you just can't access them b/c they're
private.
Object.cos(1)
NoMethodError: undefined method `cos' for Object:Class
from (irb):1
irb(main):002:0> include Math
=> Object
irb(main):003:0> Object.cos(1)
NoMethodError: private method `cos' called for Object:Class
from (irb):3
irb(main):004:0> class << Object
irb(main):005:1> public :cos
irb(main):006:1> end
=> #<Class:Object>
irb(main):007:0> Object.cos(1)
=> 0.54030230586814