I’m using: ruby 1.8.1 (2004-01-27) [i386-mswin32]
When I run the following program it works fine:
···
####################################################
require ‘tk’
root = TkRoot.new { title “Example 1” }
TkLabel.new(root){
text "Hello, World!"
pack { padx 15; pady 15; side ‘left’ }
}
Tk.mainloop
####################################################
But when I run this version:
####################################################
require ‘tk’
root = TkRoot.new { title “Example 1” }
TkLabel.new(root)
{
text "Hello, World!"
pack { padx 15; pady 15; side ‘left’ }
}
Tk.mainloop
####################################################
I get the following:
hello.rbw:7: syntax error
text “Hello, World!”
^
hello.rbw:7: warning: unused literal ignored
hello.rbw:9: syntax error
####################################################
The only difference between the two versions is the
insertion of a CR/LF between “)” and “{” on line 7.
I thought Ruby was whitespace neutral. What is wrong
here?
I care about this because I like to line up my braces
as shown in the second example.
Hi,
It’s not a bug, it’s expected behavior. The problem is that when you
are passing a block, it must begin on the same line as the function you
are passing it to. It’s almost like an argument. So, you you have three
choices:
- put the opening brace on the function call’s line, as in the first
example;
- use do…end instead of braces (since braces were really intended for
single-line code anyway (please don’t flame me!!!))
- petition Matz?
Ruby is not whitespace-neutral. It uses newlines as statement
separators.
–Mark
···
On Mar 6, 2004, at 1:29 PM, Gregory Benjamin wrote:
I’m using: ruby 1.8.1 (2004-01-27) [i386-mswin32]
When I run the following program it works fine:
####################################################
require ‘tk’
root = TkRoot.new { title “Example 1” }
TkLabel.new(root){
text “Hello, World!”
pack { padx 15; pady 15; side ‘left’ }
}
Tk.mainloop
####################################################
But when I run this version:
####################################################
require ‘tk’
root = TkRoot.new { title “Example 1” }
TkLabel.new(root)
{
text “Hello, World!”
pack { padx 15; pady 15; side ‘left’ }
}
Tk.mainloop
####################################################
I get the following:
hello.rbw:7: syntax error
text “Hello, World!”
^
hello.rbw:7: warning: unused literal ignored
hello.rbw:9: syntax error
####################################################
The only difference between the two versions is the
insertion of a CR/LF between “)” and “{” on line 7.
I thought Ruby was whitespace neutral. What is wrong
here?
I care about this because I like to line up my braces
as shown in the second example.