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 trial

Ruby

Derailed at Instance Methods

Cannot replicate the procedures shown in Jason Seifer's Instance Methods video. When I type in the subl command, I get an error message. That was about two hours ago, but I think it said it was unacceptable. The problem seems to be I'm unable to create a file (simple_methods.rb) in whatever editor Jason is using. I can write it in nano, but can't figure out how to run it. I'm assuming the "subl" command refers to Sublime2, which I downloaded and installed as instructed, several badges ago, but have never used. I must have missed something along the way. Anyway, I'm lost. And something ate the bread crumbs. Help, Mr. Wizard!

Instance Methods

1) I tried textEdit and nano, but don't know how to put the file in the proper place. I know that sounds ridiculous, but it's true.

2) I did open the Sublime Text2 app. But, again, don't know how run it.

3) I'm running 10.9.4 on a Mac mini.

4) I did install ruby. I have not tried using the ruby simple_methods.rb command.

Since I closed the terminal, I assume I'm going to have to go back and install the gem awesome_print. I guess I will back track and go from there.

Thanks for your response. I hope the link shows up. I'm not really sure how to do that either.

Here's what happens when I use the terminal furnished by the Utilities app:

Richards-Mac-mini:~ ricstr$ mkdir -p Source/methods Richards-Mac-mini:~ ricstr$ cd Source/methods Richards-Mac-mini:methods ricstr$ touch simple_methods.rb Richards-Mac-mini:methods ricstr$ subl simple_methods.rb -bash: subl: command not found

. . . and when I use the command you suggested:

Richards-Mac-mini:methods ricstr$ ruby simple_methods.rb Richards-Mac-mini:methods ricstr$

. . . it seems to work. If not getting an error message means it's working. But what next?

(While I'm thinking about it, what I'd really like to know is how to shorten my prompt by eliminating "Richards-Mac-mini:")

Now, here's the embarrassing part. I don't know where to write the code, so that it can be run.

Say I am using nano, since it's the only thing I've been able to link to ruby:

At 1:05 in the video, when the screen fades to the "simple_methods.rb" file in which the code is about to be written, what is that? Is it a terminal? A browser? A text editor? A workspace? I don't recognize it.

Richards-Mac-mini:methods ricstr$ subl simple_methods.rb -bash: subl: command not found Richards-Mac-mini:methods ricstr$ nano simple_methods.rb Richards-Mac-mini:methods ricstr$ ruby simple_methods.rb Hello world Richards-Mac-mini:methods ricstr$

I can get the code to run in nano on the Utilities terminal, but I want to approximate what is on the video.

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Please link the video you are referring to. And remember that:

1) you don't have to use sublime text 2 - you're programming, use any editor you want! no need to do every single step as in the videos

2) you don't need to open sublime text using terminal's subl command (I never do), you can simply open the application

3) you can manually create a shortcut to make the subl command usable - what system are you on?

Did you install Ruby on your system? You should be able to run the file from the terminal using the command ruby simple_methods.rb when you're in the proper folder.

Instance Methods

1) I tried textEdit and nano, but don't know how to put the file in the proper place. I know that sounds ridiculous, but it's true.

2) I did open the Sublime Text2 app. But, again, don't know how run it.

3) I'm running 10.9.4 on a Mac mini.

4) I did install ruby. I have not tried using the ruby simple_methods.rb command.

Since I closed the terminal, I assume I'm going to have to go back and install the gem awesome_print. I guess I will back track and go from there.

Thanks for your response. I hope the link shows up. I'm not really sure how to do that either.

Here's what happens when I use the terminal furnished by the Utilities app:

Richards-Mac-mini:~ ricstr$ mkdir -p Source/methods Richards-Mac-mini:~ ricstr$ cd Source/methods Richards-Mac-mini:methods ricstr$ touch simple_methods.rb Richards-Mac-mini:methods ricstr$ subl simple_methods.rb -bash: subl: command not found

. . . and when I use the command you suggested:

Richards-Mac-mini:methods ricstr$ ruby simple_methods.rb Richards-Mac-mini:methods ricstr$

. . . it seems to work. If not getting an error message means it's working. But what next?

(While I'm thinking about it, what I'd really like to know is how to shorten my prompt by eliminating "Richards-Mac-mini:")

Now, here's the embarrassing part. I don't know where to write the code, so that it can be run.

Say I am using nano, since it's the only thing I've been able to link to ruby:

At 1:05 in the video, when the screen fades to the "simple_methods.rb" file in which the code is about to be written, what is that? Is it a terminal? A browser? A text editor? A workspace? I don't recognize it.

Richards-Mac-mini:methods ricstr$ subl simple_methods.rb -bash: subl: command not found Richards-Mac-mini:methods ricstr$ nano simple_methods.rb Richards-Mac-mini:methods ricstr$ ruby simple_methods.rb Hello world Richards-Mac-mini:methods ricstr$

I can get the code to run in nano on the Utilities terminal, but I want to approximate what is on the video.

I don't understand why this isn't working for me:

class BankAccount
  def initialize(first_name, last_name)
    @balance = 0
    @first_name = first_name
    @last_name = last_name
  end
end

bank_account = BankAccount.new(β€œRichard”, β€œStringfellow”)
puts bank_account.inspect

I've typed it in exactly as shown in the video. Here is the result:

Richards-Mac-mini:methods ricstr$ ruby bank_account.rb bank_account.rb:9:in <main>': undefined local variable or methodβ€œRichard”' for main:Object (NameError) Richards-Mac-mini:methods ricstr$