ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button
  Ruby/Tk Primer: Creating a cron GUI Interface with Ruby/Tk
Subject:   Answer to the self.puts dilema
Date:   2004-07-19 16:12:40
From:   Merc
Response to: Answer to the self.puts dilema

Just a style note. Unlike Python, Ruby doesn't require parentheses around method calls that take no arguments (in fact, under most circumstances, it doesn't require them around methods that take arguments). That's why you can say puts "Hello World!", rather than puts("Hello World!").

Most Ruby programmers omit them when they're not necessary, so they would write that code:

class MyClass
def sayHello()

def hello
puts "Hello, World!!!"

myClass = MyClass.new

Part of the reason this is significant is that it allows you to treat functions as if they were attributes:

class ComplexNumber
attr_accessor :real, :complex

n = ComplexNumber.new
n.real = 5
n.complex = 6

puts "(#{n.real}, #{n.complex})"

n.real, and n.real= are actually method calls, but by omitting parentheses they look more natural.

1 to 2 of 2
  1. Answer to the self.puts dilema
    2004-07-19 20:30:53  Christopher Roach | O'Reilly Blogger [View]

  2. Answer to the self.puts dilema
    2004-07-19 16:18:43  Merc [View]

1 to 2 of 2