[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

what is the difference between two block?

Vellingiri Arul

10/30/2007 9:03:00 AM

Dear friends,
What is the difference between do .. end block and { .. }.
Is there any big difference.while doign the program more than one do and
also we can have inside one do .. end.
like this
do
puts hai
do
puts
end
end
And aslo ,same as the { .. ; {....} }
I wan to know the difference,I feel soething is there,but i am not able
to findout the answers for this.
Anybody help me please.

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

15 Answers

Sebastian Hungerecker

10/30/2007 9:12:00 AM

0

Arul hari wrote:
> What is the difference between do .. end block and { .. }.

Precedence. Other than that there is no difference, but it's convention to use
{} for single-line blocks and do end for multi-line blocks.

HTH,
Sebastian
--
Jabber: sepp2k@jabber.org
ICQ: 205544826

Vellingiri Arul

10/30/2007 9:26:00 AM

0

Sebastian Hungerecker wrote:
> Arul hari wrote:
>> What is the difference between do .. end block and { .. }.
>
> Precedence. Other than that there is no difference, but it's convention
> to use
> {} for single-line blocks and do end for multi-line blocks.
>
> HTH,
> Sebastian

Dear friend,
How do you say single line blocks and multi-line blocks.
We can use both the methods are multi-line blocks.
could you say some example.
I can't understand what you are saying?

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

Sebastian Hungerecker

10/30/2007 9:41:00 AM

0

Arul hari wrote:
> Sebastian Hungerecker wrote:
> > it's convention to use
> > {} for single-line blocks and do end for multi-line blocks.
>
> How do you say single line blocks and multi-line blocks.

Ehrm, I open my mouth and the words come out? I don't quite understand
your question.


> We can use both the methods are multi-line blocks.

You can use {} as well as do end for multi-line blocks, yes (I'm assuming
that's what you meant to convey with the above sentence, although honstly I
had some trouble parsing that). But it's *convention* to use do end for
multi-line blocks. It's only convention, it's not enforced by ruby. As I
said: the only real difference is precedence.


> could you say some example.

10.times {|i|
bar=something(i)
foo=bar.some_thing_else
puts foo
} # Discouraged

10.times do |i|
bar=something(i)
foo=bar.some_thing_else
puts foo
end # Encouraged


HTH,
Sebastian
--
Jabber: sepp2k@jabber.org
ICQ: 205544826

Vellingiri Arul

10/30/2007 10:03:00 AM

0

Sebastian Hungerecker wrote:
> Arul hari wrote:
>> Sebastian Hungerecker wrote:
>> > it's convention to use
>> > {} for single-line blocks and do end for multi-line blocks.
>>
>> How do you say single line blocks and multi-line blocks.
>
> Ehrm, I open my mouth and the words come out? I don't quite understand
> your question.
>
>
>> We can use both the methods are multi-line blocks.
>
> You can use {} as well as do end for multi-line blocks, yes (I'm
> assuming
> that's what you meant to convey with the above sentence, although
> honstly I
> had some trouble parsing that). But it's *convention* to use do end for
> multi-line blocks. It's only convention, it's not enforced by ruby. As I
> said: the only real difference is precedence.
>
>
>> could you say some example.
>
> 10.times {|i|
> bar=something(i)
> foo=bar.some_thing_else
> puts foo
> } # Discouraged
>
> 10.times do |i|
> bar=something(i)
> foo=bar.some_thing_else
> puts foo
> end # Encouraged
>
>
> HTH,
> Sebastian

Dear friends,

Thanks all of guys especially for sebastian for his deep
explanation.

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

Robert Dober

10/30/2007 11:07:00 AM

0

On 10/30/07, Sebastian Hungerecker <sepp2k@googlemail.com> wrote:
> Arul hari wrote:
> > What is the difference between do .. end block and { .. }.
>
> Precedence. Other than that there is no difference, but it's convention to use
> {} for single-line blocks and do end for multi-line blocks.
>
I fail to see that convention often personally I try to adhere to a
different convention I have seen recently:

I use {} if the value of the block is used and do end when it is all
about side effects,

example:

[ ... ].map{|x| x.to_s}
# note that under that convention map do end disappears almost

vs.

[ ... ].each do | x |
puts x
end # yes I know that puts [ ... ] does the same ,)

HTH
Robert



--
what do I think about Ruby?
http://ruby-smalltalk.blo...

Vellingiri Arul

10/30/2007 12:58:00 PM

0

Peña, Botp wrote:
> From: Arul hari [mailto:hariharan.spc@rediffmail.com]
> # I wan to know the difference,I feel soething is there,but i
> # am not able to findout the answers for this.
>
> there is difference, but not much
>
>> def f a,b
>> yield a,b
>> end
>
> precedence issue:
>
>> f 1,2 {|x,y| p x,y}
> SyntaxError: compile error
> (irb):33: syntax error, unexpected '{', expecting $end
> f 1,2 {|x,y| p x,y}
> ^
>
>> f 1,2 do|x,y| p x,y end
> 1
> 2
>
> as always, it is safe by enclosing parameters w parens
>
>
> irb(main):035:0> f(1,2) {|x,y| p x,y}
> 1
> 2
>
> irb(main):036:0> f(1,2) do|x,y| p x,y end
> 1
> 2
>
> also, one-liner chain fans sees do-end as noisy and sensitive to spacing
> (since do-ends are keywords)
>
> irb(main):037:0> [1,2,3].map{|x| 2*x}.map{|x|x+1}
> => [3, 5, 7]
> irb(main):038:0> [1,2,3].map do|x| 2*x end.map do |x|x+1 end
> => [3, 5, 7]
> irb(main):039:0> [1,2,3].mapdo|x| 2*x end.map do |x|x+1 end
> SyntaxError: compile error
> (irb):39: syntax error, unexpected kEND, expecting $end
> [1,2,3].mapdo|x| 2*x end.map do |x|x+1 end
> ^
>
> nonetheless, i like both. i particularly like do-end since i like typing
> fast without using shift. but if you have editors like textmate or
> similar, no need :)
>
> kind regards -botp

Dear Friend,
You have told me that with example,but that is not suitable for me.
I have not changed anything from that,simple I have but one bracket.
It will not shows any error.
So,Your example also not suitable for my questions.
Please tell me some more examples with exaplantion.

def f a,b
yield a,b
end
nil
f 1,2 {|x,y| p x,y}
SyntaxError: compile error
(irb):4: syntax error, unexpected '{', expecting $end
f 1,2 {|x,y| p x,y}
^
from (irb):4
from :0
f 1,2 do|x,y| p x,y end
1
2
nil
f (1,2) {|x,y| p x,y}
(irb):6: warning: don't put space before argument parentheses
1
2
nil
f (1,2){|x,y| p x,y}
(irb):7: warning: don't put space before argument parentheses
1
2
nil

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

Ian J. Ball

7/30/2013 4:30:00 PM

0

In article <707fv8h6qc5he8im20jrp2os221jl9vbfb@4ax.com>,
David <dimlan17@yahoo.com> wrote:

> On Mon, 29 Jul 2013 22:52:41 -0700, "Ian J. Ball"
> <ijball-NO_SPAM@mac.invalid> wrote:
>
> >In article <dk4ev8hvbbh7b12dnp7skf4smre57mpoc1@4ax.com>,
> > David <dimlan17@yahoo.com> wrote:
> >
> >> http://variety.com/2013/tv/news/the-cw-developing-supernatural-sp...
> >> 569
> >> 355/
> >>
> >> The CW Developing ?Supernatural? Spinoff
> >> Spinoff will be planted in a spring episode of 'Supernatural'
> >> by AJ Marechal
> >>
> >> The CW is planning a spinoff for ?Supernatural,? and will seed the
> >> project in an episode of the long-running drama next spring.
> >>
> >> From Warner Bros. TV, spinoff will explore the clashing hunter and
> >> monster cultures in Chicago. The planted episode will serve as a pilot
> >> and introduce new characters, which will anchor the spinoff.
> >
> >As others have pointed out, this isn't a "spinoff" but a "backdoor
> >pilot".
>
> That's a type of spinoff.

No, it's really not.

*You*, of all people, should know this!! :o

--
"Surf-crazed aliens... Of course." - Amber, "Alien Surf Girls",
Episode #1.1, "Wipeout".
Wait a minute... "Of course"?! "*Of course*"?!! Did I miss a step here??!!

Jim G.

7/30/2013 6:11:00 PM

0

Ian J. Ball sent the following on 7/30/2013 12:52 AM:
> In article <dk4ev8hvbbh7b12dnp7skf4smre57mpoc1@4ax.com>,
> David <dimlan17@yahoo.com> wrote:
>
>> http://variety.com/2013/tv/news/the-cw-developing-supernatural-spino...
>> 355/
>>
>> The CW Developing ?Supernatural? Spinoff
>> Spinoff will be planted in a spring episode of 'Supernatural'
>> by AJ Marechal
>>
>> The CW is planning a spinoff for ?Supernatural,? and will seed the
>> project in an episode of the long-running drama next spring.
>>
>> From Warner Bros. TV, spinoff will explore the clashing hunter and
>> monster cultures in Chicago. The planted episode will serve as a pilot
>> and introduce new characters, which will anchor the spinoff.
>
> As others have pointed out, this isn't a "spinoff" but a "backdoor
> pilot".

To be fair, there *is* that "serve as a pilot" bit there, as well.
Sounds like the writer wanted to hedge his/her bets. :)

> "Variety" of all people should know the difference.
>
>> CW employed a similar spinoff strategy with ?The Originals,? a
>> ?Vampire Diaries? spinoff that was seeded in an episode of ?TVD.? ?The
>> Originals? is slated to debut this fall.
>
> No, that *was* a spinoff, as it used long-running characters from TVD.

To be fair again, there *is* that "a similar spinoff" bit there.

> Again, "Variety" of all people should really know the difference here...

I don't go out of my way to follow the Hollywood press beyond what I see
posted here, but from that limited exposure, Variety seems to employ
relatively competent writers, with emphasis on the "relatively."

--
Jim G. | A fan of the good and the bad, but not the mediocre
"Dang it. That was my best Dirty Harry. He might just be an idiot." --
Jason Stackhouse, TRUE BLOOD

Anim8rFSK

7/30/2013 7:35:00 PM

0

In article <kt8v77$10b$10@dont-email.me>,
"Jim G." <jimgysin@geemail.com.invalid> wrote:

> Ian J. Ball sent the following on 7/30/2013 12:52 AM:
> > In article <dk4ev8hvbbh7b12dnp7skf4smre57mpoc1@4ax.com>,
> > David <dimlan17@yahoo.com> wrote:
> >
> >> http://variety.com/2013/tv/news/the-cw-developing-supernatural-sp...
> >> 569
> >> 355/
> >>
> >> The CW Developing ?Supernatural? Spinoff
> >> Spinoff will be planted in a spring episode of 'Supernatural'
> >> by AJ Marechal
> >>
> >> The CW is planning a spinoff for ?Supernatural,? and will seed the
> >> project in an episode of the long-running drama next spring.
> >>
> >> From Warner Bros. TV, spinoff will explore the clashing hunter and
> >> monster cultures in Chicago. The planted episode will serve as a pilot
> >> and introduce new characters, which will anchor the spinoff.
> >
> > As others have pointed out, this isn't a "spinoff" but a "backdoor
> > pilot".
>
> To be fair, there *is* that "serve as a pilot" bit there, as well.
> Sounds like the writer wanted to hedge his/her bets. :)

Ooo! Oooo! They've come up with a new term for it:
"planted spinoff episode"

--
Wait - are you saying that ClodReamer was wrong, or lying?

David

7/30/2013 10:35:00 PM

0

On Tue, 30 Jul 2013 09:30:07 -0700, "Ian J. Ball"
<ijball-NO_SPAM@mac.invalid> wrote:

>In article <707fv8h6qc5he8im20jrp2os221jl9vbfb@4ax.com>,
> David <dimlan17@yahoo.com> wrote:
>
>> On Mon, 29 Jul 2013 22:52:41 -0700, "Ian J. Ball"
>> <ijball-NO_SPAM@mac.invalid> wrote:

>> >As others have pointed out, this isn't a "spinoff" but a "backdoor
>> >pilot".
>>
>> That's a type of spinoff.
>
>No, it's really not.

Maybe I'd recognize your authority on this if you hadn't stopped
maintaining a TV newsgroup faq.

>*You*, of all people, should know this!! :o

I know another term for "backdoor pilot" is "planted spinoff."