Ruby Ruby Foundations Blocks Working With Blocks

Charles Strawn
Charles Strawn
3,462 Points

example2.rb is not working in Ruby version 2.0.0p353

Hello.

When I attempt to run the example2.rb file, I only get "Hello, world" returned. It looks as though the second puts statement is not returned.

Could it be that the instructor is running Ruby version 1.9.3, and I am running Ruby version 2.0.0p353?

def say_hello(&block)
  puts "Hello, World"
  name = block.call
  puts = "You entered #{name} as your name."
end

say_hello { "Jason" }

1 Answer

Brandon Barrette
Brandon Barrette
20,481 Points

What exactly are you getting? When I run this in 2.2.1 it works just fine.

Charles Strawn
Charles Strawn
3,462 Points

It just returns "Hello, World".

It does not display "You entered Jason as your name.", like it does in the video.

Brandon Barrette
Brandon Barrette
20,481 Points

Huh. I'm not sure what to tell you. Upgrade your version of ruby? The current stable version of 2.0 is 2.0.0-p645 and the current stable version of ruby is 2.2.2

Charles Strawn
Charles Strawn
3,462 Points

Hello Brandon.

The problem with that as I see it, is the the instructor of the course is using version 1.9.3, and it works for him. It also works for you on a newer version. So this is a bit confusing.

I have also had other issues because I am using a newer version than the instructor, but I am mostly able to work around them.

My fear is that using an even newer version will make it worse.

What do you think Brandon?