hi Paet,
welcome to ruby!
so, there are a few things with your code that are a little ‘strange.’
first - i’m not sure about defining classes as:
class self.WhatTheHeck
##
end
i think that’s where you /n (or newline) error is coming from, and i’m
not sure that this works at all - ditch the 'self’s.
second, remember that methods reside within the class you create them
in - so in line 25 when you call thoughtp.testforaccess
from within
the Startup class, Startup has no idea what thoughttp
is, nor what the
method testforaccess
is.
also, in line 40, you define a method called Steveloaded
- classes,
modules, and constants start with capital letters, not methods - this
will throw an error for sure.
i think that maybe what you’re trying to do is to instantiate one
class from within another, and then call some methods on the instance of
the first class from within the other. that’s no sweat… take a look
at something simple like this:
class Bicycle
def initialize
p “#{self} - i’m a 3 speed bike”
@gear = 1
end
def change_gear
p “#{self} was in gear #{@gear}”
@gear +=1
@gear = 1 if @gear > 3
p “and now #{self} is in gear #{@gear}”
end
end
class Automobile
def initialize
p “#{self} - i’m an automobile”
@speed = 55
end
def accelerate
p “#{self} was going at #{@speed} mph”
@speed += 15
p “and now #{self} is going at #{@speed} mph”
end
end
class ThingsWithWheels
def initialize
p “these are things with wheels…”
bike = Bicycle.new
car = Automobile.new
sleep(1.5)
bike.change_gear
sleep(1.5)
car.accelerate
end
end
rolling_stuff = ThingsWithWheels.new
is that something more like what you were after? notice too that i
use instance variables (variables that start with @
) instead of global
variables (which start with $
.) global variables are generally a bad
idea - they tend to muck up the works sometimes. instance variables can
be accessed from any method of a particular instance of a class, and
generally do the job quite well.
hth, keep at it!