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 Ruby Foundations Objects, Classes, and Variables Review

Yashar Soroosh
Yashar Soroosh
5,617 Points

gets on text mate

Hello All. For some reason gets is not working for me on Textmate. Furthermore, Textmate does not recognize chomp. Below is my code, please let me know what I'm doing wrong.

`` class BankAccount def initialize(name) @transaction=[] @balance=0 end

def deposit
    print("How Much Do You Want to Deposit?")
    amount = gets.chomp
    @balance=amount.to_f
    puts "$#{amount} deposited."
end

def show_balance
    puts "your balance is #{@balance}"
end
 end

bank_account = BankAccount.new("Some One") bank_account.deposit bank_account.show_balance

4 Answers

Jamie McCaw
Jamie McCaw
5,579 Points

Textmate is basically a fancy wordpad and probably isn't what is causing the main issue for you. I was able to take your code from above put it into an irb repl and run it with no issues. If you could post the actual errors you are getting that would be helpful in further trouble shooting for you.

I rewrote the code just incase to make it easier to copy and paste:

class BankAccount

  def initialize(name)
    @transaction = []
    @balance = 0
  end

  def deposit
    print("How much do you want to deposit? ")
    amount = gets.chomp
    @balance = amount.to_f
    puts "$#{amount} deposited."
  end

  def show_balance
    puts "Your balance is: #{@balance}"
  end

end

bank_account = BankAccount.new("Some One")
bank_account.deposit
#Here you need to wait and enter the amount
bank_account.show_balance
Yashar Soroosh
Yashar Soroosh
5,617 Points

Sorry for the delay. Here is the error message.

Users/yasharsoroosh/Downloads/TextMate.app/Contents/SharedSupport/Bundles/Ruby.tmbundle/Support/RubyMate/catch_exception.rb:12:in for_fd': Bad file descriptor (Errno::EBADF) from /Users/yasharsoroosh/Downloads/TextMate.app/Contents/SharedSupport/Bundles/Ruby.tmbundle/Support/RubyMate/catch_exception.rb:12:inblock in <top (required)>' /Users/yasharsoroosh/Documents/Ruby Programming Treehouse/bank_account.rb:9:in deposit': undefined methodchomp' for nil:NilClass (NoMethodError) from /Users/yasharsoroosh/Documents/Ruby Programming Treehouse/bank_account.rb:21:in `<main>'

Jamie McCaw
Jamie McCaw
5,579 Points

Ok that is a bit better. Basically when you get any message like "undefined method:chomp, for nil:NilClass" it's telling you that you tried to perform that method on nothing. In the code from above we are calling 'chomp' on the the users input, what this tells me is that you are probably not getting the input for some reason.

Try comparing my code with what you have and see if you might have a typo somewhere. I've tested the code I posted above and know it works the way intended.

Yashar Soroosh
Yashar Soroosh
5,617 Points

Hi Jamie,

I tried your code as well it give me the same error. Could it be a TextMate error?