[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: to_str behavior

Howard Roberts

8/13/2007 7:44:00 AM

Nasir Khan wrote:
> Hi,
Greetings Nasir,

> class MyTest < Test::Unit::TestCase
> def test_equality
> x = B.new("hello")
> assert_equal("hello", x)
> end
> end
>
> Which failed to my surprise.
> 1) Failure:
> test_equality(MyTest) [(irb):49]:
> <"hello"> expected but was
> <#<B:0x27549bc @value="hello">>.
>
> 1 tests, 1 assertions, 1 failures, 0 errors
Okay, as the results showed, an object "x" of class MyTest does not
equal the
string results of the method .to_str called on the x object.

assert_equal ("hello", x.to_str)

is what you want :)

> class B < String
> def initialize(str)
> @value = str
> end
> def to_s
> @value
> end
> def to_str
> to_s
> end
> end
>
> irb(main):023:0* a = B.new("hello")
> => ""
> irb(main):024:0>
> irb(main):025:0*
> irb(main):026:0* puts a
>
> => nil
>
> Which surprised me even more.
No surprise here, either. You have added a method, to_str to the String
class,
but when you instantiated the Object you did not make any assignment to
the string itself.

If you say, for example:

b= String.new
puts b

you would get the same result, because this is essentially the same
thing.
In your a class, a.to_str should work, I believe, but in my mind, all
bets are off because you are changing the behavior of the built-in
String class, which is generally "a bad thing" unless you are very
careful.

Cheers,

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

5 Answers

DeepDudu

1/26/2011 2:19:00 PM

0

On Wed, 26 Jan 2011 04:38:34 -0800 (PST), syvyn11
<robhorine711@yahoo.com> wrote:

>On Jan 26, 7:34?am, Lon Jimmes <corvus...@gmail.com> wrote:
>> HEADLINE: Nancy Pelosi says Obama created more jobs in 2010 than G. W.
>> Bush did in eight years
>>
>> OVERVIEW: In comments right after Obama's State of the Union speech,
>> Pelosi rips into Bush and the GOP, saying that Obama created more US
>> jobs in 2010 alone than Bush did in all his eight years.
>>
>> LINK:http://www.examiner.com/american-politics-in-vancouver/pelo......
>
>Is this woman senile? Unemployment under Bush averaged 5.5
>
>UNEMPLOYMENT NOW UNDER OBAMA? 9.5!
>
>So how does the math work on that.

OK, you're a complete idiot.....

http://www.academycomputerservice.com/economics/...

find a liberal to explain the funny graph thingies to you.

DeepDudu

1/26/2011 2:20:00 PM

0

On Wed, 26 Jan 2011 07:42:07 -0600, "Wull" <wmailey@sbcglobal.net>
wrote:

>
>"syvyn11" <robhorine711@yahoo.com> wrote in message
>news:2586e6e8-c1f7-4c68-8411-be841ed22f7e@k21g2000prb.googlegroups.com...
>On Jan 26, 7:34 am, Lon Jimmes <corvus...@gmail.com> wrote:
>> HEADLINE: Nancy Pelosi says Obama created more jobs in 2010 than G. W.
>> Bush did in eight years
>>
>> OVERVIEW: In comments right after Obama's State of the Union speech,
>> Pelosi rips into Bush and the GOP, saying that Obama created more US
>> jobs in 2010 alone than Bush did in all his eight years.
>>
>> LINK:http://www.examiner.com/american-politics-in-vancouver/pelo......
>
>Is this woman senile? Unemployment under Bush averaged 5.5
>
>UNEMPLOYMENT NOW UNDER OBAMA? 9.5!
>
>So how does the math work on that.
>
>Obviously syv, she never passed arithmetic. And the cameras never once
>showed her last night during the Presidential speech.
>

Wrong on both counts, because they did. At least once. You must
have been in the fridge getting another Bud.

http://www.academycomputerservice.com/economics/...

>Wull
>

Cliff

1/27/2011 10:30:00 AM

0

On Wed, 26 Jan 2011 04:38:34 -0800 (PST), syvyn11 <robhorine711@yahoo.com>
wrote:

>On Jan 26, 7:34?am, Lon Jimmes <corvus...@gmail.com> wrote:
>> HEADLINE: Nancy Pelosi says Obama created more jobs in 2010 than G. W.
>> Bush did in eight years
>>
>> OVERVIEW: In comments right after Obama's State of the Union speech,
>> Pelosi rips into Bush and the GOP, saying that Obama created more US
>> jobs in 2010 alone than Bush did in all his eight years.
>>
>> LINK:http://www.examiner.com/american-politics-in-vancouver/pelo......
>
>Is this woman senile? Unemployment under Bush averaged 5.5
>
>UNEMPLOYMENT NOW UNDER OBAMA? 9.5!

Bushco & the rethugs trashed the US & world economy.

>
>So how does the math work on that.

More private sector jobs now.

Though the rethugs plan to cut all jobs a LOT.
--
Cliff

Cliff

1/27/2011 10:31:00 AM

0

On Wed, 26 Jan 2011 07:42:07 -0600, "Wull" <wmailey@sbcglobal.net> wrote:

>Is this woman senile? Unemployment under Bush averaged 5.5

Well, he did start out with the glowing Clinton economy
to trash.
--
Cliff

rfischer

1/29/2011 9:13:00 AM

0

syvyn11 <robhorine711@yahoo.com> wrote:
>On Jan 26, 7:34?am, Lon Jimmes <corvus...@gmail.com> wrote:
>> HEADLINE: Nancy Pelosi says Obama created more jobs in 2010 than G. W.
>> Bush did in eight years
>>
>> OVERVIEW: In comments right after Obama's State of the Union speech,
>> Pelosi rips into Bush and the GOP, saying that Obama created more US
>> jobs in 2010 alone than Bush did in all his eight years.
>>
>> LINK:http://www.examiner.com/american-politics-in-vancouver/pelo......
>
>Is this woman senile? Unemployment under Bush averaged 5.5

When Bush left office the US was losing 700,000+ jobs EVERY MONTH!

But you're a dumbass rightard who doesn't know shit except right wing
propaganda.

--
Ray Fischer | Mendacracy (n.) government by lying
rfischer@sonic.net | The new GOP ideal