Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Announcing Reg 0.4.0

Reply
Thread Tools

Announcing Reg 0.4.0

 
 
Ilmari Heikkinen
Guest
Posts: n/a
 
      04-26-2005

On 26.4.2005, at 20:35, Christian Neukirchen wrote:

> It is already very confusing that String !=== String (what is the most
> elegant way to case compare classes against classes, btw?).


I don't know about elegant, but this is probably the way that requires
least typing:

def make_new(klass)
case [klass]
when [String]: "foo"
when [Fixnum]: 27
when [Array]: [nil, nil, true]
end
end

make_new String
=> "foo"

Ilmari Heikkinen
--
66. The regions beyond these places are either difficult of access
because of their excessive winters and great cold, or else cannot be
sought out because, of some divine influence of the gods.



 
Reply With Quote
 
 
 
 
David A. Black
Guest
Posts: n/a
 
      04-26-2005
Hi --

On Wed, 27 Apr 2005, vikkous wrote:

> I wrote:
>
>> I'm not sure about Christian, but I think itsme213 meant
>> sort of the opposite: how does your system relate to the
>> duck-typing environment of Ruby, where type != class
>> (i.e., an object's capabilities and its class's instance
>> methods are not necessarily the same thing)? Are you
>> thinking of extending the system so that it could match,
>> for example, "an array of objects that respond to '[]'"

>
> Oh! Ok, well that's easy, it would be something like:
>
> +[ proceq{|x| x.respond_to? :[] }+1 ]
>
> Being forced to use a proceq (gawd that's a terrible name) here is a
> little ugly. Eventually, I want to be able to pass arguments to
> property matchers, so the above could be:
>
> +[ -{ [:respond_to?, :[]]=>true }+1 ]


I wonder whether one could combine this with tests for class ancestry,
by matching a class/module name (#is_a?) and, at the same time,
verifying that the object's capabilities are a match for its ancestry.
Or something. I haven't puzzled it through very deeply.

>> duck typing per se, as I understand it, really means just
>> requesting action from objects without a lot of preliminary
>> querying and measuring (whether it be is_a?, respond_to?,
>> or whatever).

>
> If you're doing something complicated, you occasionally have to
> explicity request the type (whether duck- or class-) of objects you're
> working with, in order to do the right thing with it. I know this isn't
> polymorphic, but sometimes it is the right way...


I'd tend to say: if it's the type, it's not the class, and if you have
to explicitly request it, it's not duck-typing But yes, I think
there are occasions for all these things, in various combinations.
As others have often pointed out, respond_to? != duck typing, but I do
tend to think of respond_to?-based logic as a kind of "weak duck
typing", if that isn't too arcane. It falls short of the true "Here,
do this!" spirit of true duck typing, but undeniably (in my view) has
a foot in the same camp, in that it factors in the dynamism of type.


David

--
David A. Black
http://www.velocityreviews.com/forums/(E-Mail Removed)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Announcing RouteMonitor 1.0 Beta pbopardi@gmail.com Cisco 2 07-08-2005 06:51 AM
Windows Reg Pro vs Tweak now Reg Cleaner vs Registry fix, vs RegCleaner jl Computer Support 3 05-31-2005 12:53 AM
Anyone know anything named DX? (was Re: Announcing PyCs) (was:Announcing PyCs, a new Python-like language on .Net) Mark Hahn Python 22 09-09-2004 12:14 PM
announcing routes to split network Philipp Specht Cisco 2 01-23-2004 11:05 AM
Announcing Limited Public Beta - XHTML 1.0 Strict Web Controls Peter L. ASP .Net 0 10-20-2003 08:14 PM



Advertisments