Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
More on the fundamentals...
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Matthew Smillie, post: 4499528"] You've made a couple of fundamental mistakes regarding how methods are defined. The basic schema is: def method_name(parameter_name) Where you can have a whole list of parameters, or none at all. See the revised (and very verbose comments. Hope this helps. matt smillie. Also, I've changed the indented to two spaces, since that's the Ruby norm. class Greeter # open class Greeter (it's not necessarily *new*) def initialize(name) # defining the initialise method, which is called when a new # object is created. The method takes one parameter, 'name'. # Example (such as: foo = Greeter.new("Mark"). @name = name # define an instance variable called '@name' and assign it # the value of the parameter 'name' end def say(phrase) # defining a new method called 'say' with a parameter # called 'phrase'. puts "#{phrase}, #{@name}" # The double quotes define a string, and the #{} sections are # used for interpolation (substitution). end end [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
More on the fundamentals...
Top