# Noob: Code review my first tutorial homework assignment?

**URL:** <https://www.ruby-forum.com/t/noob-code-review-my-first-tutorial-homework-assignment/154333>\
**Category:** Ruby\
**Created:** [November 27, 2008, 8:51pm UTC](https://www.ruby-forum.com/t/noob-code-review-my-first-tutorial-homework-assignment/154333 "2008-11-27T20:51:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zakifataya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/c89c15/32.png) [@zakifataya](https://www.ruby-forum.com/u/zakifataya)\
**Post date:** [November 27, 2008, 8:51pm UTC](https://www.ruby-forum.com/t/noob-code-review-my-first-tutorial-homework-assignment/154333/1 "2008-11-27T20:51:00Z")

</div>

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}

---

<div class="post-metadata">

**Author:** ![zakifataya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/c89c15/32.png) [@zakifataya](https://www.ruby-forum.com/u/zakifataya)\
**Post date:** [November 27, 2008, 9:13pm UTC](https://www.ruby-forum.com/t/noob-code-review-my-first-tutorial-homework-assignment/154333/2 "2008-11-27T21:13:46Z")

</div>

On Thu, Nov 27, 2008 at 8:46 PM, Brian A.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> yield(parameters, current\_month)  
> A: 2  
> Q: How many paramaters do you pass into the block

> my\_instance.my\_own\_ruby\_method(“alpha”, “beta”){|s|puts s}  
> A: 1  
> Q: I am sure you know it by now.  
> Cheers  
> Robert  
> –  
> Ne baisse jamais la tête, tu ne verrais plus les étoiles.

Robert D. 😉

---

<div class="post-metadata">

**Author:** ![zakifataya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/c89c15/32.png) [@zakifataya](https://www.ruby-forum.com/u/zakifataya)\
**Post date:** [November 28, 2008, 4:34am UTC](https://www.ruby-forum.com/t/noob-code-review-my-first-tutorial-homework-assignment/154333/3 "2008-11-28T04:34:39Z")

</div>

Robert D. wrote:

> On Thu, Nov 27, 2008 at 8:46 PM, Brian A.  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > yield(parameters, current\_month)  
> > A: 2  
> > Q: How many paramaters do you pass into the block
> 
> > my\_instance.my\_own\_ruby\_method(“alpha”, “beta”){|s|puts s}  
> > A: 1  
> > Q: I am sure you know it by now.  
> > Cheers  
> > Robert  
> > –  
> > Ne baisse jamais la tï¿½te, tu ne verrais plus les ï¿½toiles.
> 
> Robert D. 😉

Thank you for the help. Does this look better? It runs with no error  
and seems to make sense to me… Any input is appreciated:

=================================================================================

# 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(my\_parameter, your\_parameter, current\_month)

```
# 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  
)  
yield(my\_parameter, your\_parameter, current\_month)

end  
end

my\_instance = MyOwnRubyClass.new

current\_month = Date.today.month

my\_instance.my\_own\_ruby\_method(“alpha”, “beta”, Date.today.month){|arg1,  
arg2, arg3| puts “#{arg1} #{arg2} #{arg3}”}

---

<div class="post-metadata">

**Author:** ![zakifataya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/c89c15/32.png) [@zakifataya](https://www.ruby-forum.com/u/zakifataya)\
**Post date:** [November 28, 2008, 12:05pm UTC](https://www.ruby-forum.com/t/noob-code-review-my-first-tutorial-homework-assignment/154333/4 "2008-11-28T12:05:03Z")

</div>

On Fri, Nov 28, 2008 at 4:29 AM, Brian A.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Robert D. wrote:  
> Better, but there is still two yields in your method, one with one  
> parameter one with three.  
> If this is really needed I would rather declare the block with  
> variable arguments look at this  
> 514/15 \> irb  
> irb(main):001:0\> def a( \*args, &blk)  
> irb(main):002:1\> blk.call( _args )  
> irb(main):003:1\> end  
> =\> nil  
> irb(main):004:0\> myblock = proc{ |args| case  
> irb(main):005:2 when args.empty?  
> irb(main):006:2\> puts “empty”  
> irb(main):007:2\> when args.size==1  
> irb(main):008:2\> puts args.first  
> irb(main):009:2\> else  
> irb(main):010:2_ p args  
> irb(main):011:2\> end  
> irb(main):012:1\> }  
> =\> #Proc:0xb7d2f78c@:4(irb)  
> irb(main):013:0\> a &myblock  
> empty  
> =\> nil  
> irb(main):014:0\> a 1, &myblock  
> 1  
> =\> nil  
> irb(main):015:0\> a 42, 222, 22, &myblock  
> [42, 222, 22]  
> =\> nil  
> irb(main):016:0\>

–  
Ne baisse jamais la tête, tu ne verrais plus les étoiles.

Robert D. 😉

---

<div class="post-metadata">

**Author:** ![zakifataya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/c89c15/32.png) [@zakifataya](https://www.ruby-forum.com/u/zakifataya)\
**Post date:** [November 28, 2008, 10:50pm UTC](https://www.ruby-forum.com/t/noob-code-review-my-first-tutorial-homework-assignment/154333/5 "2008-11-28T22:50:12Z")

</div>

On Thu, Nov 27, 2008 at 11:46 AM, Brian A.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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.

Also, check out Satish T.'s free ruby class:

> **[Learn How to Blog and Build Websites for Profit!](https://heyblogging.com/)**
>
> Ready to take your blogging skills to the next level? Learn how to build a website that generates income and sets you up for success.

martin
