Skip to content

Instantly share code, notes, and snippets.

@dtothefp
Created April 3, 2014 12:39
Show Gist options
  • Save dtothefp/9953528 to your computer and use it in GitHub Desktop.
Save dtothefp/9953528 to your computer and use it in GitHub Desktop.
Classes & Prototypes
class Car
def initialize(name)
@name = name
end
def name
@name
end
end
car = Car.new "I'm a new Car"
puts car.name
############
class Truck
attr_accessor :name
end
truck = Truck.new
truck.name = "I'm a new truck"
puts truck.name
#############
class Pinto
def name
@name
end
def name=(something)
@name = something
end
end
pinto = Pinto.new
pinto.name = "I'm a new Pinto"
puts pinto.name
class Hoopty
attr_reader :name
def initialize(name)
@name = name
end
end
hoopty = Hoopty.new "dope ass hoopty"
puts hoopty.name
class DopeRide
attr_reader :name
attr_writer :name
end
dope_ride = DopeRide.new
dope_ride.name = "johhny"
puts dope_ride.name
function Car(name) {
this.name = name;
}
Car.prototype.drive = function(driving) {
if (driving) {
return this.name + " is driving"
} else {
return this.name + " step on the gas fuckstick"
}
}
car = new Car("johhny");
console.log(car.drive(false));
anotherCar = new Car("Chris");
console.log(anotherCar.drive(true));
function LittleCar() {}
LittleCar.prototype = car;
LittleCar.prototype.fuckedUp = function(isFucked) {
if (isFucked) {
return this.name + " is fucked up";
} else {
return this.name + " is a sweet ride!!!!"
}
}
var smallerCar = new LittleCar();
console.log(smallerCar.fuckedUp(true));
var carObj = {
name: function(name) {
return name;
},
drive: function(driving) {
if (driving) {
return this.name + " is driving"
} else {
return "step on the gas fuckstick"
}
}
}
console.log(carObj.name("jimmy"));
console.log(carObj.drive(true));
console.log(carObj.drive(false));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment