Skip to content

Instantly share code, notes, and snippets.

def take_block(number, &block)
block.call
end
[1, 2, 3, 4, 5].each do |number|
take_block number do
puts "Block being called in the method! #{number}"
end
end
class BadDog
def initialize(name) # instance method
@name = name # instance veriable
end
def get_name # getter method
@name
end
def change_info(n, h, w)
self.name = n
self.height = h
self.weight = w
end
def change_info(n, h, w)
@name = n
class Animal
def speak
"Hello!"
end
end
class GoodDog < Animal
attr_accessor :name
def initialize(n)
module Drive
def speed_up( num )
self.speed += num
puts "you accelerate by #{num} and are now travelling at #{speed} mph."
end
def slow_down( num )
self.speed -= num
puts "You decrease your speed by #{num} and are now travelling at #{speed}"
end
module Drive
def speed_up( num )
self.speed += num
puts "you accelerate by #{num} and are now travelling at #{speed} mph."
end
def slow_down( num )
self.speed -= num
puts "You decrease your speed by #{num} and are now travelling at #{speed}"
end
module VehicleAge
def age
some code....
puts "Your #{VEHICLETYPE} is x years old"
end
end
class MyCar
VEHICLETYPE = "car"
@jheg
jheg / gist:0cca034ba9dc7245ee09
Created October 22, 2014 21:26
Constant issues
module Drive
def speed_up( num )
self.speed += num
puts "you accelerate by #{num} and are now travelling at #{speed} mph."
end
def slow_down( num )
self.speed -= num
puts "You decrease your speed by #{num} and are now travelling at #{speed}"
end
<script type="text/javascript">
$(window).load(function() {
// The slider being synced must be initialized first
$('#carousel').flexslider({
animation: "slide",
controlNav: false,
animationLoop: false,
slideshow: false,
itemWidth: 210,
@jheg
jheg / gist:944720d364dc1648f260
Created November 1, 2014 22:49
class variable inrement
# start new game
# ask players name
# introduce opponent from random opponents
# display info regarding current oponent wins/ties/losses
# player picks hand ( paper(p), rock(r) or scissors(s) )
# opponent picks hand
# result
# play again