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
1
vote
2 answers

Ruby Exercise 18 undefined method although i defined the methods

Hi i get the error "undefined method" in the exercise 18 although i did it like its written. class Exercise18_NamesVariablesCodeFunctions # this one is like your scripts with ARGV def print_two(*args) arg1, arg2 = args puts "arg1: #{arg1},…
1
vote
3 answers

Assigning .read Results to a Variable? (Learn Ruby The Hard Way Ex. 15/16)

I'm brand new to programming and I'm working on Learn Ruby The Hard Way. In Exercise 15 he shows how to open and read a text file, and how to print that to the screen. In the next exercise, he briefly mentions at the beginning that the '.read'…
1
vote
2 answers

Multiple variable assignment with each_with_index

I have this code snippet, a bucket in this case is just an array within a larger array: def Dict.get_slot(aDict, key, default=nil) # Returns the index, key, and value of a slot found in a bucket. bucket = Dict.get_bucket(aDict, key) …
Magnus
  • 31
  • 1
  • 6
1
vote
1 answer

Texts in a file not printing properly

Working through this problem and I have typed out the code EXACTLY like the problem states - even tried to copy and paste to see if it was something I was doing wrong but its not. The code that I have is at the bottom of this post. I am sending the…
RubyRocker
  • 13
  • 2
1
vote
1 answer

Assert_equal undefined local variable LRTHW ex52

Hi I made it to the lase exercise os Learn Ruby The Hard Way, and I come at the wall... Here is the test code: def test_gothon_map() assert_equal(START.go('shoot!'), generic_death) assert_equal(START.go('dodge!'), generic_death) room…
Kazik
  • 705
  • 1
  • 8
  • 20
1
vote
2 answers

Ruby for statement using undefined variables

I'm a beginner at programming, and I'm trying to complete Zed Shaw's book for Ruby, and I just cannot understand the last for statement of the code. If the variables state and abbrev have not been defined, how does the software know where to get…
Amir
  • 197
  • 2
  • 17
1
vote
1 answer

"Undefined method 'close'" when trying to close a file in Ruby

I'm working through "Learn Ruby the Hard Way" and receive an undefined method 'close' error when trying to run the example file here: http://ruby.learncodethehardway.org/book/ex17.html My code, specifically is: from_file, to_file = ARGV script =…
Kyle Chadha
  • 3,741
  • 2
  • 33
  • 42
1
vote
3 answers

Learn Ruby the Hard Way ex17 extra credit 3 - consolidating to one line

For exercise 17, through searching other responses I was able to condense the following into one line (as asked in the extra credit #3) from_file, to_file = ARGV script = $0 input = File.open(from_file) indata = input.read() output =…
user2498045
  • 141
  • 1
  • 5
0
votes
3 answers

Stuck on Zed Shaw's ruby exercise

I am basically halfway done with Zed Shaw's introduction to Ruby course. However, I am stuck at a roadblock with this exercise where he gives me a piece of code and asks me to fix it. Alot of the errors were grammatical but some of the coding ones…
F F
  • 391
  • 1
  • 3
  • 6
0
votes
2 answers

Stand alone method is calling another method by itself

Ok i seriously suck at passing method to methods whenever i want to return something from the method. Can you guys explain on how do i go about passing it. Here's my hash $choosen_gun = {} $Weapon = { :Bazoka => ["Bazoka",5], :Machine_gun =>…
Suresh
  • 39
  • 6
0
votes
1 answer

Not displaying it's corresponding values with it's key for Hash

Ok i am not here to ask for an answer. But to be honest i am not really good in class variable. So i would appreciate you can guide me along with this piece of code. I have read on class variable at those docs. I some what kind of understand it. But…
Suresh
  • 39
  • 6
0
votes
0 answers

Ruby: Error changing variables with methods

I've been trying to learn Ruby so I can build a website and was told that Learning Ruby the Hard Way was a good place to start. I've been doing the exercises, but got stuck at ex36. We are supposed to write a mini text based decision game (pick your…
Zero
  • 1
  • 2
0
votes
1 answer

LoadError when requiring Sinatra Gem in app

I'm following the tutorial http://learnrubythehardway.org/book/ex50.html, which provides: create the most basic Sinatra application possible. Put the following code into bin/app.rb: require 'sinatra' set :port, 8080 set :static, true set…
0
votes
1 answer

Ruby The Hard Way Exercise 13 ARGV not working in PowerShell

I am using: ruby 2.2.4p230 (2015-12-16 revision 53155) [x64-mingw32] Notepad ++ PowerShell v. 1.0 on Windows When I run the code below in PowerShell: first, second, third = ARGV puts "Your first variable is: #{first}" puts "Your second variable…
Artur S.
  • 19
  • 4
0
votes
1 answer

"Learn ruby the hard way" missing puts output on exercise 14

I'm currently working on exercise 14 with a friend, which is some really simple string interpolation and user input grabbing. My code looks like this: user_name = ARGV.first prompt = '>…
Mikey T.K.
  • 1,112
  • 18
  • 43