Instantly share code, notes, and snippets.

View gist:4335648
car = Car.new(2300)
car.log(100)
=> "The car has logged 100 miles, totaling 2400 miles traveled."
car.log(354)
=> "The car has logged 354 miles, totaling 2754 miles traveled."
car.log(300)
=> "The car has logged 300 miles, totaling 3054 miles traveled."
=> "The car needs to be taken in for service!"
View gist:4335632
class Notifier
def update(car, miles)
puts "The car has logged #{miles} miles, totaling #{car.mileage} miles traveled."
puts "The car needs to be taken in for service!" if car.service <= car.mileage
end
end
require 'observer'
class Car
View gist:4335615
class Notifier
def update(car, miles)
puts "The car has logged #{miles} miles, totaling #{car.mileage} miles traveled."
puts "The car needs to be taken in for a service!" if car.service <= car.mileage
end
end
View gist:4335614
class Car
attr_reader :mileage, :service
def initialize(mileage = 0, service = 3000)
@mileage, @service = mileage, service
end
def log(miles)
@mileage += miles
end
View gist:4335345
$ ruby neo4j_example.rb
View gist:4335319
require 'rubygems'
require 'bundler/setup'
require 'neo4j'
Neo4j::Transaction.run do
me = Neo4j::Node.new(:name => 'Me', :age => 31)
bob = Neo4j::Node.new(:name => 'Bob', :age => 29)
mark = Neo4j::Node.new(:name => 'Mark', :age => 34)
mary = Neo4j::Node.new(:name => 'Mary', :age => 32)
john = Neo4j::Node.new(:name => 'John', :age => 33)
View gist:4335305
require 'rubygems'
require 'bundler/setup'
require 'neo4j'
Neo4j::Transaction.run do
me = Neo4j::Node.new(:name => 'Me', :age => 31)
bob = Neo4j::Node.new(:name => 'Bob', :age => 29)
mark = Neo4j::Node.new(:name => 'Mark', :age => 34)
mary = Neo4j::Node.new(:name => 'Mary', :age => 32)
john = Neo4j::Node.new(:name => 'John', :age => 33)
View gist:4335297
require 'rubygems'
require 'bundler/setup'
require 'neo4j'
Neo4j::Transaction.run do
# our code here
end
View neo4j_example.rb
require 'rubygems'
require 'bundler/setup'
require 'neo4j'
Neo4j::Transaction.run do
me = Neo4j::Node.new(:name => 'Me', :age => 31)
bob = Neo4j::Node.new(:name => 'Bob', :age => 29)
mark = Neo4j::Node.new(:name => 'Mark', :age => 34)
mary = Neo4j::Node.new(:name => 'Mary', :age => 32)
john = Neo4j::Node.new(:name => 'John', :age => 33)
View gist:4335224
$ gem install 'neo4j'