Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJillian Dunleavy
3,685 PointsWould someone help me with this ruby block objective?
Call the method get_name with a block. Assign the block argument a variable called name. Do at least one thing in the block such as printing out the name.
I've tried a few variations that relate to what I had in the workspace during the video, but I can't get it.
def get_name
name = "My Name"
name = gets.chomp
yield name
end
name - get name do
puts #{name}
end
2 Answers
Jeff Wilkey
10,296 PointsYou're kind of close you should be closer to something more along the lines of this:
def get_name
name = "Jillian"
yield name
end
# Write your code here
get_name do |name|
puts "#{name}"
end
Jesse Zelaya
13,599 PointsTry this:
def get_name
print "Enter your name: "
name = gets.chomp
yield name
name
end
name = get_name do |name|
puts "That's a cool name, #{name}!"
end
Jillian Dunleavy
3,685 PointsThanks for helping me out.
Jeff Wilkey
10,296 PointsJeff Wilkey
10,296 PointsI suggest trying to watch the video again to understand the syntax here a bit better.
Jillian Dunleavy
3,685 PointsJillian Dunleavy
3,685 PointsThanks for helping me out.