Questions tagged [learn-ruby-the-hard-way]

Learn Ruby the Hard Way is a free online book on the Ruby language for beginner programmers. It's an adaptation of Zed Shaw's Learn Python the Hard Way translated into Ruby by Rob Sobers.

Learn Ruby the Hard Way is a free online book on the Ruby language for beginner programmers. It's an adaptation of Zed Shaw's Learn Python the Hard Way translated into Ruby by Rob Sobers. It can be found here.

42 questions
21
votes
2 answers

What is "Syntax Error, unexpected tCONSTANT" error in Ruby?

I am currently on Lesson 9 in "Learn Ruby the hard way". I have typed the the line number 6 exactly as the way its being instructed but still I am getting error while executing. It says: Syntax error, unexpected tCONSTANT, expecting $end puts "…
The Realmccoy
  • 329
  • 1
  • 2
  • 9
12
votes
2 answers

Proper Assert_Raise Unit Testing and Use of Exception Class

I am working on Exercise 49 of Learn Ruby the Hard Way The exercise asks to write a unit test for each function provided. One of the items I am testing is if a proper exception is raised. It is suggested that we use assert_raise for this…
8
votes
2 answers

Require command not working within bash irb on Snow Leopard

I am working on Zed Shaw's Learn Ruby the Hard Way Exercise 25 http://ruby.learncodethehardway.org/ex25.html When I navigate to the directory that holds the ruby file ex25.rb and launch IRB, I get these errors: Larson-2:~ larson$ cd…
Andrew Lauer Barinov
  • 5,694
  • 10
  • 59
  • 83
6
votes
2 answers

Ruby Basics: Pop Method in Array

I'm working my way through Learning Ruby the Hard Way online; I've just finished the 26th exercise which was a "test" whereby you fixed someone's broken code. My problem came with using an argument with the pop method. I'm familiar with the basics…
helipacter
  • 103
  • 1
  • 1
  • 4
4
votes
2 answers

gets.chomp inside a function in ruby

I'm going through "Learn Ruby the Hard Way" and on exercise 20 there is a snippet of code that I don't understand. I don't understand why gets.chomp is called on f in the function "print_a_line". input_file = ARGV.first def print_all(f) puts…
Sean Szurko
  • 244
  • 1
  • 3
  • 16
3
votes
2 answers

Nested Loop: to be dynamic?

Ok i'm actually doing this exercise to tackle those nested loop questions. I would say this would be the hardest one for me. I tried my best to be more dynamic instead of static. Can anyone give me tips on how to solve this? expected output: 1 1 2 1…
Suresh
  • 39
  • 6
3
votes
1 answer

Ruby gets.chomp and $stdin.gets.chomp difference

filename = ARGV.first txt = open(filename) puts "Here's your file #{filename}:" print txt.read print "Type the filename again: " file_again = $stdin.gets.chomp Here is my question if I change it to gets.chomp it doesn't work why ? txt_again =…
Gent Binaku
  • 55
  • 11
3
votes
1 answer

Ruby Include Module in IRB

I'm working through Zed Shaw's Learn Ruby The Hard Way and I'm having an issue including a module in IRB. In exercise 25, we define a new module Ex25, require it in IRB, and then can use its various methods through the namespace of that module,…
orenyk
  • 452
  • 5
  • 9
2
votes
3 answers

While Loops in Ruby and Converting to a Function

I'm on Chapter 33 of Learn Ruby the Hard Way. Extra credit exercise 1 asks: Convert this while loop to a function that you can call, and replace 6 in the test (i < 6) with a variable. The code: i = 0 numbers = [] while i < 6 puts "At the top…
Stn
  • 437
  • 1
  • 6
  • 15
2
votes
1 answer

Strange Error when Unit Testing a particular function in Ruby

I'm working on this Exercise 49 in Learn Ruby the Hard Way The exercise asks to write a unit test for each function provided. One of the unit tests I am writing is giving me an error. Here is the code I am testing (word_list is an array of Pair…
Andrew Lauer Barinov
  • 5,694
  • 10
  • 59
  • 83
2
votes
2 answers

Push an array into another array with Ruby, and return square brackets

I've spent a few hours searching for a way to push an array into another array or into a hash. Apologies in advance if the formatting of this question is bit messy. This is the first time I've asked a question on StackOverflow so I'm trying to get…
2
votes
2 answers

load 'file.rb' versus require 'Module' in Ruby

I am confused about the difference between load 'file.rb' and require 'Module'. At Learn Ruby the Hard Way, the example of how to use a module is set up with two files (mystuff.rb and apple.rb): mystuff.rb module MyStuff def MyStuff.apple() …
David
  • 51
  • 7
2
votes
1 answer

Learn Ruby the Hardway ex. 42. 2 classes in 2 files

I understand how classes work and how to make them, but the 2nd extra credit of the exercice says to create a two-class version, in 2 different files. I tried different things, but I can't figure out how to make it work... I don't know if I'm not…
Jauny
  • 950
  • 1
  • 8
  • 19
2
votes
1 answer

Ruby Name Error - Uninitialized constant

I am doing exercises and am getting NameError:Unitialized Constant MyUnitTests::Room when running test_ex47.rb. test_ex47.rb: require 'test/unit' require_relative '../lib/ex47' class MyUnitTests < Test::Unit::TestCase def test_room() …
septerr
  • 6,445
  • 9
  • 50
  • 73
1
vote
6 answers

How do I create a paragraph in Ruby?

I am running through a tutorial and even though I have typed this code exactly as instructed it is coming back with a syntax error. Can anyone explain how to create a paragraph in ruby? My attempt is shown below. Thanks Puts <
shfury
  • 389
  • 1
  • 5
  • 15
1
2 3