Is this behavior correct? 
Author Message
 Is this behavior correct?

Hello --

Quote:

> --cut--
> Hit ENTER or type command to continue
> class Bar
>     def initialize(*children)
>         puts "Init "+children.to_s
>     end
> end

> foo =  Bar.new("Alpha");
> foo =  Bar.new
>     ("Beta");
> --cut--
> --stdout--
> Init Alpha
> Init
> --stdout--

> Ruby version: ruby 1.6.7 (2002-03-01) [i686-linux]

> If it is correct?  If so, can someone point me at some documentation
> about where whitespace is important to Ruby?

Yes, it's correct.  Use -w and you'll get a hint :-)

$ ruby -w corbin.rb
corbin.rb:9: warning: useless use of a literal in void context
Init Alpha
Init

So the second Bar.new has no argument, and the ("Beta") is just sort
of sitting there.  I'm not sure of the exact formulation of the
rule...  (see Pickaxe), but the newline will be significant (end of
statement) generally unless the line ends with a binary operator.

  puts 3 +
  4           # => 7

  puts 3
  + 4         # => 3

(and maybe other circumstances I'm not thinking of)

David

--
David Alan Black


Web:   http://www.*-*-*.com/ ~blackdav



Tue, 28 Sep 2004 05:05:41 GMT  
 Is this behavior correct?

Quote:
> So the second Bar.new has no argument, and the ("Beta") is just sort
> of sitting there.  I'm not sure of the exact formulation of the
> rule...  (see Pickaxe), but the newline will be significant (end of
> statement) generally unless the line ends with a binary operator.

Basically whenever Ruby knows that it's in the middle of something (an
expression, a parameter list, etc, or immediately following a
backslash, newlines are ignored. Otherwise they terminate the
statement.

Cheers

Dave



Tue, 28 Sep 2004 06:10:32 GMT  
 Is this behavior correct?

Quote:

>$ ruby -w corbin.rb
>corbin.rb:9: warning: useless use of a literal in void context
>Init Alpha
>Init

>So the second Bar.new has no argument, and the ("Beta") is just sort
>of sitting there.  I'm not sure of the exact formulation of the
>rule...  (see Pickaxe), but the newline will be significant (end of

I did look at the Pickaxe, but I couldn't find where it says that.
Quote:
>statement) generally unless the line ends with a binary operator.



Tue, 28 Sep 2004 06:48:34 GMT  
 Is this behavior correct?
--cut--
Hit ENTER or type command to continue
class Bar
    def initialize(*children)
        puts "Init "+children.to_s
    end
end

foo =  Bar.new("Alpha");
foo =  Bar.new
    ("Beta");
--cut--
--stdout--
Init Alpha
Init
--stdout--

Ruby version: ruby 1.6.7 (2002-03-01) [i686-linux]

If it is correct?  If so, can someone point me at some documentation
about where whitespace is important to Ruby?

Thanks
David Corbin



Tue, 28 Sep 2004 07:53:41 GMT  
 Is this behavior correct?

Quote:

> >So the second Bar.new has no argument, and the ("Beta") is just sort
> >of sitting there.  I'm not sure of the exact formulation of the
> >rule...  (see Pickaxe), but the newline will be significant (end of

> I did look at the Pickaxe, but I couldn't find where it says that.

Page 201 (the start of the language reference) mentions it

Dave



Tue, 28 Sep 2004 08:15:32 GMT  
 Is this behavior correct?
Hi --

Quote:


> > So the second Bar.new has no argument, and the ("Beta") is just sort
> > of sitting there.  I'm not sure of the exact formulation of the
> > rule...  (see Pickaxe), but the newline will be significant (end of
> > statement) generally unless the line ends with a binary operator.

> Basically whenever Ruby knows that it's in the middle of something (an
> expression, a parameter list, etc, or immediately following a
> backslash, newlines are ignored. Otherwise they terminate the
> statement.

I *knew* I was being too barebones :-)

David

--
David Alan Black


Web:  http://pirate.shu.edu/~blackdav



Tue, 28 Sep 2004 08:42:25 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Am I on the correct track?

2. correct behavior

3. the correct behavior

4. correct Numeric behavior?

5. Correct behavior for file-write-date?

6. Correct behavior for failure during __init__()

7. Correct behavior for failure during __init__()

8. Tk4.0b: please correct the binding behavior

9. I am not deaf, but am I mute?

10. is this a bug or is it behavior of which I am not aware?

11. archive announcement, corrected

12. Do you prove your APL programs correct?

 

 
Powered by phpBB® Forum Software