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 trialgerald blady
9,052 Pointsname error
getting the following error message.. it's regarding account = BankAccount.new('my name')
the error message is
(NameError)
from logging-example.rb:30:in new'
from logging-example.rb:30:in
<main>'
require 'logger'
class BankAccount attr_reader :file_logger, :stdout_logger
def initialize(name)
@name = name
@transactions = []
@logger = logger.new(STDOUT)
@file_logger = Logger.new("./bank_account.log")
end
def deposit(amount)
log "depositing #{amount}"
@transactions.push(amount)
end
def withdraw(amount)
log "withdraring #{withdraw}"
@transactions.push(-amount)
end
def log(message, level=Logger::INFO)
file_logger.add level, message, "#{self.class} (#{name})"
stdout_logger.add level, message, "#{self.class} (#{name})"
end
end
account = BankAccount.new('my name') account.depost(100) account.withdraw(50)
6 Answers
steven alston
16,292 Pointsyou forgot to add the @ symbol
file_logger.add level, message, "#{self.class} (#{@name})" stdout_logger.add level, message, "#{self.class} (#{@name})"
Unsubscribed User
3,309 PointsSophie, you're missing a ':', change the line to attr_reader :file_logger, :stdout_logger
Iain Simmons
Treehouse Moderator 32,305 PointsYour @logger
property should be accessing the Logger
class (i.e. beginning with a capital 'L').
Change that and see how you go...
gerald blady
9,052 Pointsthat was a small error but doesn't seem to be what i'm looking for.
Iain Simmons
Treehouse Moderator 32,305 PointsSorry, you also haven't changed the @logger
property to @stdout_logger
as Jason described in the video.
gerald blady
9,052 Pointsgonna have to rewatch and type out tomorrow. appreciate the swift reply
Sophia Harrison
4,534 PointsI have the exact same issue minus the typo issues :
require 'logger'
class BankAccount
attr_reader :file_logger, stdout_logger
def initialize(name)
@name = name
@transactions = []
@stdout_logger = Logger.new(STDOUT)
@flie_logger = Logger.new("./bank_account.log")
end
def deposit(amount)
log "Depositing #{amount}"
@transactions.push(amount)
end
def withdraw(amount)
log "Withdrawing #{amount}"
@transactions.push(-amount)
end
def log(message, level=Logger::INFO)
file_logger.add level, message, "#{self.class} (#{@name})"
stdout_logger.add level, message, "#{self.class} (#{@name})"
end
end
account = BankAccount.new("Sophia Harrison")
account.deposit(100)
account.withdraw(50)