From: "Brian A." Date: 2008-11-28T04:46:05+09:00 Subject: Noob: Code review my first tutorial homework assignment? Hello! Im reading through tutorials to teach myself Ruby. I'm a business programmer by day, but I want to learn something new instead of the same old thing I've been doing for the last 8 years. I don't know any Ruby programmers local to me, so I'd like to ask you to please code review the first half of my 'project'. If I am doing something wrong, or could do it better please remember Im just a ruby-noob so please explain it as best you can so I can understand why I should do things differently. Thank you much in advance! Here is what I was asked to do (note this is only the first half of the project, but Id like to know Im headed in the right direction before I start the second half). ================================================== # Name the project as MyOwnRubyApp. # Create a new Ruby class called MyOwnRubyClass. # Define a method called my_own_ruby_method inside of the MyOwnRubyClass class as following * The method receives two parameters called my_parameter and your_parameter. * The method then prints out current time using Time.now. * The method then invokes yield(my_parameter, your parameter, current_month). o The current_month, is an integer value representing current month of the year, for example, for the current month of "June", the current_month should be 6. o The current_month value needs to computed in your program. For example, if you are running the same program during July, it should be set to 7. (In other words, you cannot pass hard-coded value in your program) # Create an instance of MyOwnRubyClass. Assign it to a variable called my_instance. ================================================== Here is my code. It runs but I get this error also "...My Documents/NetBeansProjects/HomeWorkLab1/lib/main.rb:23: warning: multiple values for a block parameter (2 for 1) from .../My Documents/NetBeansProjects/HomeWorkLab1/lib/main.rb:17" ================================================== # Create a class called MyOwnRubyClass class MyOwnRubyClass # define a method called my_own_ruby_method # method receives two parameters called my_parameter and your_paramter def my_own_ruby_method(*parameters) # method prints our current time using Time.now yield(Time.now) # 1) The method then invokes yield(my_parameter, your parameter, current_month) # 2) The current_month, is an integer value representing current month of the year, # for example, for the current month of "June", the current_month should be 6. # 3) The current_month value needs to computed in your program. # For example, if you are running the same program during July, it should be set to 7. # (In other words, you cannot pass hard-coded value in your program) current_month = Date.today.month #yield "#{parameters.join(',')}", current_month{|x| puts x} # doesnt work yield(parameters, current_month) end end my_instance = MyOwnRubyClass.new my_instance.my_own_ruby_method("alpha", "beta"){|s|puts s} ================================================== -- Posted via http://www.ruby-forum.com/.