[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

creating a <=> method

Dirk Meijer

12/11/2005 9:30:00 PM

hi everyone,
i've created a class, and want it to be comparable with itself, but i don't
know what to place inside the <=> method.
the basic idea is that one of the values of the class (which is a symbol) is
converted to a string, which is then compared.
greetings, Dirk.
6 Answers

James Gray

12/11/2005 9:33:00 PM

0

On Dec 11, 2005, at 3:29 PM, Dirk Meijer wrote:

> hi everyone,
> i've created a class, and want it to be comparable with itself, but
> i don't
> know what to place inside the <=> method.
> the basic idea is that one of the values of the class (which is a
> symbol) is
> converted to a string, which is then compared.

Like this?

def <=>( other )
sym.to_s <=> other.sym.to_s
end

James Edward Gray II


gabriele renzi

12/11/2005 9:36:00 PM

0

Dirk Meijer ha scritto:
> hi everyone,
> i've created a class, and want it to be comparable with itself, but i don't
> know what to place inside the <=> method.
> the basic idea is that one of the values of the class (which is a symbol) is
> converted to a string, which is then compared.
> greetings, Dirk.
>

yuu should return 1 if self > b, 0 if self == b and -1 otherwise.
You can generally realy on some other <=>, i.e.

>> Foo= Struct.new :someval do
?> def <=> other
>> someval.to_s <=> other.someval.to_s
>> end
>> include Comparable
>> end
=> Foo
>> f1=Foo.new "ciao"
=> #<struct Foo someval="ciao">
>> f2=Foo.new "miao"
=> #<struct Foo someval="miao">
>> f1 < f2
=> true
>> f1 >= f2
=> false

hope this helps

Dirk Meijer

12/11/2005 9:40:00 PM

0

2005/12/11, James Edward Gray II <james@grayproductions.net>:
>
> Like this?
>
> def <=>( other )
> sym.to_s <=> other.sym.to_s
> end
>
> James Edward Gray II


it works, thanks! :D
didn't think it would be that simple..
greetings, Dirk.

Eero Saynatkari

12/11/2005 9:44:00 PM

0

Dirk Meijer wrote:
> hi everyone,
> i've created a class, and want it to be comparable with itself, but i
> don't
> know what to place inside the <=> method.
> the basic idea is that one of the values of the class (which is a
> symbol) is
> converted to a string, which is then compared.

# The spaceship operator needs to return either
# -1, 0 or 1 depending on whether it is 'smaller',
# 'equal' or 'greater' than the other object.
def <=>(other)
# We can use String#<=> here if both are Strings.
# Otherwise implement some custom comparison as above.
@my_value.to_s <=> other.to_s
end


> greetings, Dirk.

E


--
Posted via http://www.ruby-....


Larry Hewitt

12/16/2011 11:38:00 PM

0

On 12/16/2011 6:20 PM, Steve wrote:
> On Fri, 16 Dec 2011 11:38:41 -0800 (PST), "Read what Frederic Bastiat
> wrote."<johnnaishwerner@yahoo.com> wrote:
>
>> On Dec 14, 1:48 am, MattB<notrdell1...@gmail.comspam.> wrote:
>>> US calls for ban on in-car phone use ... even with Bluetooth
>>>
>>> http://usnews.msnbc.msn.com/_news/2011/12/13/9418504-us-cal......
>>>
>>> Updated at 4 p.m. ET: The government's transportation safety experts
>>> recommended Tuesday to ban all American drivers from using portable
>>> electronic devices ? including cellphones, even if you use a
>>> hands-free device.
>>>
>>> The recommendation, which isn't binding but which is likely to
>>> influence the decisions of Congress and state legislatures in writing
>>> new safety laws, makes only two exceptions: You could still use GPS
>>> navigation devices, and you could use your cellphone in an emergency.
>>> "No call, no text, no update, is worth a human life," Deborah Hersman,
>>> chairwoman of the National Transportation Safety Board, said at a news
>>> conference in Washington.
>>>
>>> Besides calling for government action, the NTSB also urged consumer
>>> electronics manufacturers to figure out a way to "disable the
>>> functions of portable electronic devices within reach of the driver
>>> when a vehicle is in motion" while at the same time being able to turn
>>> themselves back on in an emergency.
>>>
>>> ***********************
>>>
>>> Even bluetooth? To think people want to give Obama 4 more years.
>>> Vote Gingrich in the primary and give Obama 4 more years.
>>
>> On the surface it looks like a good idea, but it will be difficult to
>> enforce.
>
>
> Totally unenforceable. I can be, and have been happily talking on my
> cellphone while it's riding in a bag back in the bed of my pickup
> truck, and not with a cockroach bluetooth device hung on me ear,
> either.

Actually, it all depends on how hard they want to pursue this.

In the event of an accident, for ex., your phone records could get you a
heavy fine and a denial of your insurance claim.

Cops can also see your lips moving or a headset in your ear, and will
undoubtedly be able to pull you over and look at your phone's history.

Not to mention the random stop or being pulled over for another infraction.

The same lame claim was made about wearing a seatbelt.

Larry

RichTravsky

12/24/2011 4:33:00 AM

0

Matt wrote:
> On Dec 22, 2:07 pm, RichTravsky <traRvEskyM...@hotmail.com> wrote:
> > Steve wrote:
> > > On Sun, 18 Dec 2011 21:06:36 -0700, RichTravsky
> > > <traRvE...@hotmMOVEail.com> wrote:
> > > >Steve wrote:
> > > >> On Fri, 16 Dec 2011 23:03:33 -0700, RichTravsky
> > > >> <traRvE...@hotmMOVEail.com> wrote:
> > > >> >Steve wrote:
> > > >> >> On Fri, 16 Dec 2011 18:37:56 -0500, Larry Hewitt
> > > >> >> <larryh...@comporium.net> wrote:
> > > >> >> >On 12/16/2011 6:20 PM, Steve wrote:
> > > >> >> >> On Fri, 16 Dec 2011 11:38:41 -0800 (PST), "Read what Frederic Bastiat
> > > >> >> >> wrote."<johnnaishwer...@yahoo.com> wrote:
> >
> > > >> >> >>> On Dec 14, 1:48 am, MattB<notrdell1...@gmail.comspam.> wrote:
> > > >> >> >>>> US calls for ban on in-car phone use ... even with Bluetooth
> >
> > > >> >> >>>>http://usnews.msnbc.msn.com/_news/2011/12/13/9418504-us-cal......
> >
> > > >> >> >>>> Updated at 4 p.m. ET: The government's transportation safety experts
> > > >> >> >>>> recommended Tuesday to ban all American drivers from using portable
> > > >> >> >>>> electronic devices ? including cellphones, even if you use a
> > > >> >> >>>> hands-free device.
> >
> > > >> >> >>>> The recommendation, which isn't binding but which is likely to
> > > >> >> >>>> influence the decisions of Congress and state legislatures in writing
> > > >> >> >>>> new safety laws, makes only two exceptions: You could still use GPS
> > > >> >> >>>> navigation devices, and you could use your cellphone in an emergency.
> > > >> >> >>>> "No call, no text, no update, is worth a human life," Deborah Hersman,
> > > >> >> >>>> chairwoman of the National Transportation Safety Board, said at a news
> > > >> >> >>>> conference in Washington.
> >
> > > >> >> >>>> Besides calling for government action, the NTSB also urged consumer
> > > >> >> >>>> electronics manufacturers to figure out a way to "disable the
> > > >> >> >>>> functions of portable electronic devices within reach of the driver
> > > >> >> >>>> when a vehicle is in motion" while at the same time being able to turn
> > > >> >> >>>> themselves back on in an emergency.
> >
> > > >> >> >>>> Even bluetooth? To think people want to give Obama 4 more years.
> > > >> >> >>>> Vote Gingrich in the primary and give Obama 4 more years.
> >
> > > >> >> >>> On the surface it looks like a good idea, but it will be difficult to
> > > >> >> >>> enforce.
> >
> > > >> >> >> Totally unenforceable. I can be, and have been happily talking on my
> > > >> >> >> cellphone while it's riding in a bag back in the bed of my pickup
> > > >> >> >> truck, and not with a cockroach bluetooth device hung on me ear,
> > > >> >> >> either.
> >
> > > >> >> >Actually, it all depends on how hard they want to pursue this.
> >
> > > >> >> Bullshit. It's unenforceable.
> >
> > > >> >No, but it would be costly.
> >
> > > >> >> >In the event of an accident, for ex., your phone records could get you a
> > > >> >> >heavy fine and a denial of your insurance claim.
> >
> > > >> >> >Cops can also see your lips moving
> >
> > > >> >> <LOL> ...and you expect that to hold up in court?
> >
> > > >> >Yes. Similar is done in other cirumstances, suspicion of a crime in progress etc
> >
> > > >> <ROTFLMAO> Judge, the officers says that his lips were moving, so
> > > >> doesn't that constitute probably cause that he was talking on the
> > > >> phone? ...even though they saw no phone...
> >
> > > >Just hope you aren't involved in an accident while talking...
> >
> > > >> >> >or a headset in your ear, and will
> > > >> >> >undoubtedly be able to pull you over and look at your phone's history.
> >
> > > >> >> <ROTFLMAO> I wear no headset in my truck... and the phone itself
> > > >> >> might be in my briefcase in the back seat or sometimes even back in
> > > >> >> the bed of my truck.. My truck has a topper and the bed and sides are
> > > >> >> padded and carpeted so I often carry things back there..
> >
> > > >> ><ROTFLMAO> - that means you weren't using it.
> >
> > > >> <ROTFLMAO> I use it all the time loser.. hands free, bluetooth, but
> > > >> no headset..
> >
> > > ><ROTFLMAO> And all on your phone records...
> >
> > > Which requires a warrant... and....
> > > ...which means nothing unless you can prove I had the phone...
> > > ...which is in my briefcase.... which also can't be opened w/o a
> > > warrant.
> >
> > Don't need a warrant to look up your car tags. Don't need a warrant to show
> > proof of insurance. Don't need a warrant to show registration. Don't need a
> > warrant to show driver's license. Now, hand over your phone...
> >
> > That was easy. <ROTFLMAO>
>
> Lentil is an idiot. The police can search phones, that has already
> been established
> in California and Michigan.

Poor rightard.

http://articles.cnn.com/2011-01-05/tech/search.warrant.phone.gahran_1_cell-phone-text-message-drug-deal?...
>
> As for "not opened without a warrant", it is clear the Lentil knows
> nothing about police behavior. Probable cause
> is all that is needed there.


http://www.thenewspaper.com/news/3...
The Michigan State Police have a high-tech mobile forensics device that can
be used to extract information from cell phones belonging to motorists
stopped for minor traffic violations.
...


http://articles.cnn.com/2011-05-31/tech/warrantless.phone.searches_1_cell-phone-police-search-warrant-requirement?...
Warrantless cell phone searches spread to more states
...

ETC