[#237] object.c ruby.h (fwd) — Robert Skarwecki <skaav@...>

Hello everybody,

42 messages 2002/07/24
[#239] Re: [PATCH] object.c ruby.h (fwd) — GOTO Kentaro <gotoken@...> 2002/07/24

At Thu, 25 Jul 2002 00:02:28 +0900,

[#240] Re: [PATCH] object.c ruby.h (fwd) — Dave Thomas <Dave@...> 2002/07/24

GOTO Kentaro <gotoken@notwork.org> writes:

[#246] Re: [PATCH] object.c ruby.h (fwd) — GOTO Kentaro <gotoken@...> 2002/07/25

At Thu, 25 Jul 2002 05:05:46 +0900,

[#247] Re: [PATCH] object.c ruby.h (fwd) — Dave Thomas <Dave@...> 2002/07/25

GOTO Kentaro <gotoken@notwork.org> writes:

[#248] Re: [PATCH] object.c ruby.h (fwd) — nobu.nokada@... 2002/07/25

Hi,

[#249] Re: [PATCH] object.c ruby.h (fwd) — Dave Thomas <Dave@...> 2002/07/25

nobu.nokada@softhome.net writes:

[#250] Re: [PATCH] object.c ruby.h (fwd) — nobu.nokada@... 2002/07/25

Hi,

[#252] Re: [PATCH] object.c ruby.h (fwd) — GOTO Kentaro <gotoken@...> 2002/07/25

At Fri, 26 Jul 2002 03:11:02 +0900,

[#253] Re: [PATCH] object.c ruby.h (fwd) — Dave Thomas <Dave@...> 2002/07/25

GOTO Kentaro <gotoken@notwork.org> writes:

Re: [PATCH] object.c ruby.h (fwd)

From: GOTO Kentaro <gotoken@...>
Date: 2002-07-24 19:50:22 UTC
List: ruby-core #239
At Thu, 25 Jul 2002 00:02:28 +0900,
Robert Skarwecki wrote:

> A quick test shows the result:
> $ ruby -e "puts true.class.ancestors.join(',')"
> TrueClass,Object,Kernel
> $ ./ruby -e "puts true.class.ancestors.join(',')"
> TrueClass,BooleanClass,Object,Kernel

Indeed introducing Boolean may make is-a relation clear in the
mathematical sense, but I have two questions.

  * On test stage, we sometimes need is_a?(Boolean) test and `assert'
    method of RUNIT::Assert tests if the value is really true/false.
    Meanwhile, how often do we need Boolean class in run-time?

  * Every object works as a boolean parameter:
      puts 1 if "a"  # puts 1 because "a" is regarded as true value
      !!!x == !x     # true for arbitrary x
      !!!x || !!x    # true for arbitrary x

    Now, how can I explain `"a".is_a?(Boolean) == false'?

By the way, the result above can be obtained by a Ruby script below.
So, I think that Boolean should be an option activated by `require
"boolean"' even if that would be introduced.

% cat boolean.rb 
module Boolean
  def self.append_features(m)
    if m != TrueClass and m != FalseClass
      raise TypeError, "`#{m.name}' isn't TrueFalse nor FalseClass", caller(1)
    end
    super
  end
end

class TrueClass
  include Boolean
end

class FalseClass
  include Boolean
end


% ruby -r boolean -e 'puts true.class.ancestors.join(",")' 
TrueClass,Boolean,Object,Kernel
% ruby -r boolean -e 'puts false.class.ancestors.join(",")'
FalseClass,Boolean,Object,Kernel
% ruby -r boolean -e 'p true.is_a?(Boolean) && false.is_a?(Boolean)'
true
% ruby -r boolean -e 'class Array; include Boolean; end'   
-e:1:in `include': `Array' isn't TrueFalse nor FalseClass (TypeError)
        from -e:1
% 

-- Gotoken

In This Thread