Skip to content

Instantly share code, notes, and snippets.

@gisikw
Created October 27, 2010 15:48
Show Gist options
  • Save gisikw/649305 to your computer and use it in GitHub Desktop.
Save gisikw/649305 to your computer and use it in GitHub Desktop.
class CreateMedications < ActiveRecord::Migration
def self.up
create_table :medications do |t|
t.string :name
t.string :prescriber
t.date :dispense_date
t.integer :quantity
t.integer :days_supply
t.boolean :imported, :default => false
t.boolean :stopped, :default => false
t.timestamps
end
end
def self.down
drop_table :medications
end
end
class Medication < ActiveRecord::Base
end
@medication = Medication.first
@medication.name = "Prozac"
@medication.save
@medication.potency
# --> NoMethodError: undefined method `potency' for #<Medication:0x103926db0>
@medication = Medication.find_by_name("Prozac")
class Foo
["hello","goodbye","howdy"].each do |word|
eval <<-END
def say_#{word}
puts "#{word}"
end
END
end
end
f = Foo.new
f.say_hello
# --> Hello
class Foo
def method_missing(method_name)
if method_name.to_s =~ /^say_([a-z]+)$/
puts $1
else
super
end
end
end
f = Foo.new
f.say_bonjour
# --> bonjour
sum = 1 + 1
sum.class # => Fixnum
array = [1,2,3]
array << 4
array = 5
symbol = :foo
hash = {:arg1 => "val1", :arg2 => "val2"}
hash[:arg3] = "val3"
@instance_variable = "string"
def my_method(arg1)
puts arg1
end
require 'rubygems'
require 'sinatra'
get '/' do
"Welcome to the index page"
end
html
background: #ccc
body
width: 960px
margin: 0 auto
background: #fff
h1, h2
font-size: 18px
p
a
color: red
&:hover
color: purple
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment