[#4766] Wiki — "Glen Stampoultzis" <trinexus@...>

21 messages 2000/09/04
[#4768] RE: Wiki — "NAKAMURA, Hiroshi" <nahi@...> 2000/09/04

Hi, Glen,

[#4783] Re: Wiki — Masatoshi SEKI <m_seki@...> 2000/09/04

[#4785] Re: Wiki — "NAKAMURA, Hiroshi" <nakahiro@...> 2000/09/05

Howdy,

[#4883] Re-binding a block — Dave Thomas <Dave@...>

16 messages 2000/09/12

[#4930] Perl 6 rumblings -- RFC 225 (v1) Data: Superpositions — Conrad Schneiker <schneik@...>

Hi,

11 messages 2000/09/15

[#4936] Ruby Book Eng. translation editor's questions — Jon Babcock <jon@...>

20 messages 2000/09/16

[#5045] Proposal: Add constants to Math — Robert Feldt <feldt@...>

15 messages 2000/09/21

[#5077] Crazy idea? infix method calls — hal9000@...

This is a generalization of the "in" operator idea which I

17 messages 2000/09/22

[#5157] Compile Problem with 1.6.1 — Scott Billings <aerogems@...>

When I try to compile Ruby 1.6.1, I get the following error:

15 messages 2000/09/27

[ruby-talk:5166] Re: Types and ===

From: Mathieu Bouchard <matju@...>
Date: 2000-09-28 00:50:56 UTC
List: ruby-talk #5166
> AFAIK, the principal use/purpose of "===" is "case equality" for case
> statements. (IMHO this is an unfortunately somewhat over-specialized name
> for a more general concept--I would have preferred something more generic
> or more generalized such as "case matching".) Since there are so many
> sorts of relations that are not symmetric with respect to swapping their
> arguments that people might quite reasonably want to use in case
> statements, then unless I am missing something else here, I don't see how
> precluding the usage of such methods wouldn't eventually become a very
> onerous restriction.

oh, by the way, I just wrote this other case..when replacement where
the method name (:===) is a parameter.


def _when(a,&block)
        proc {|b,meth| a.send(meth,b) ? block : nil }
end

def _default(&block)
        proc {|b,meth| block }
end

def _case(b,meth,*clauses)
        clauses.each {|clause|
                block = clause.call(b,meth)
		return block.call if block
	}
end

p $*[0]
_case($*[0],:===,
        _when('bar') { p "got bar" },
        _when('qux') { p "got qux" },
	_when(/foo/) { p "got a foo thing" },
        _default { p "got something else" })


a nice trick is that you can write your own _when_not (or _unless) or
more complex conditions, like _when_any, _when_all, ...

I haven't explored replacing the method name (:===) by a block like {|a,b|
a === b}, which could be more useful.


matju



In This Thread