Skip to content

Instantly share code, notes, and snippets.

#coding: utf-8
require "rubygems"
require "rspec"
require "./step1"
describe Hoge do
describe :initialize do
subject { Hoge.new( 100, 1000) }
it "インスタンス変数aに100が代入されること" do
subject.a.should == 100
#coding: utf-8
require "rubygems"
class Hoge
attr_reader :a, :b
#aとbをインスタンス変数に格納する
def initialize a, b
@a = a
@b = b
end
@ohta-rh
ohta-rh / gist:3793712
Created September 27, 2012 12:20
namespaced model
class User < ActiveRecord::Base
has_one :profile
end
class User::Profile < ActiveRecord::Base
belongs_to :profile
end
@ohta-rh
ohta-rh / gist:3780659
Created September 25, 2012 08:35
fuckin ios6
Header set Pragma no-cache
Header set Cache-Control no-cache
Header set Expires "Thu, 01 Dec 1994 16:00:00 GMT"
@ohta-rh
ohta-rh / gist:3168758
Created July 24, 2012 08:11
Element Tree python
#coding: utf-8
from xml.etree.ElementTree import ElementTree
class Hoge :
@classmethod
def parse(cls, filepath) :
#TODO: ここにパースする処理
@ohta-rh
ohta-rh / gist:3168754
Created July 24, 2012 08:09
REXML ruby
#coding: utf-8
require "rexml/element"
class Hoge
def self.parse(filepath)
#TODO: パース処理
end
end
@ohta-rh
ohta-rh / gist:3168715
Created July 24, 2012 08:02
Ruby class method
#coding :utf-8
class Hoge
def self.say_hoge
puts "hoge"
end
end
@ohta-rh
ohta-rh / gist:3168712
Created July 24, 2012 08:01
Python class method
#coding: utf-8
class Hoge :
@classmethod
def say_hoge(cls) :
print "hoge"
@ohta-rh
ohta-rh / gist:3127914
Created July 17, 2012 08:07
[hello python!]Defined class method and class variable
#coding: utf-8
class Hoge
strategy = None
@classmethod
def set_strategy(cls, strategy) :
self.strategy = strategy || Piyo
@classmethod
def say(cls) :
return self.strategy.say()
@ohta-rh
ohta-rh / gist:3103295
Created July 13, 2012 07:10
Python XML parse sample
#coding: utf-8
from xml.etree.ElementTree import ElementTree
import urllib
url = "http://example.com/example.xml"
xml = ElementTree(file=urllib.urlopen(url))
for e in list(xml.getroot().getiterator()):
if e.tag != None and e.text != None :
print e.tag.encode("utf-8") + ":" + e.text.encode("utf-8")