Skip to content

Instantly share code, notes, and snippets.

class Ohta < ::Chu2Byou
include ::Rock::90::Nirvana
include ::Rock::90::Radiohead
include ::Book::MishimaYukio
def suicide
raise NotImplementedError
end
@ohta-rh
ohta-rh / gist:1194188
Created September 5, 2011 05:51
defile_method sample
#attrs = { foo: "foo", bar: "bar", baz: "baz" ,,,,}
class DefineMethodSample
def initialize(attrs)
attrs.symbolize_keys!
attrs.each do |k, v|
self.class.send(:define_method, k) { return(v) }
end
end
end
group :test do
gem "rspec-rails", '>=2.0.0'
gem "rspec", '>=2.0.0'
gem "rspec-core", '>=2.0.0'
gem "rspec-expectations", '>=2.0.0'
gem "rspec-mocks", '>=2.0.0'
gem 'email_spec'
gem 'rr'
end
@ohta-rh
ohta-rh / gist:2600427
Created May 5, 2012 06:43
sample code
require 'digest/md5'
class Hoge
def initialize
@data = nil
end
def data=(data)
@data = Digest::MD5::hexdigest(data)
end
@ohta-rh
ohta-rh / gist:2642895
Created May 9, 2012 08:15
Rspec sample
#sample code
class Hoge
def say(message=nil)
message ||= "hoge"
return message
end
end
#rspec
describe Hoge do
@ohta-rh
ohta-rh / gist:2833135
Last active October 5, 2015 16:07
Ruby association Silver
#coding: utf-8
#別名メソッドに気をつけよう。
#たとえば
#array.mapとarray.collectは同じメソッドです。
#自己破壊メソッドはポインタ参照が変わらないため、変数bは変数aの内容を表示する。
a = [1,2,3]
b = a
a.reverse!
p b
@ohta-rh
ohta-rh / gist:2871973
Created June 5, 2012 01:52
Hello World
#coding: utf-8
puts "Hello world"
@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")
@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:3168712
Created July 24, 2012 08:01
Python class method
#coding: utf-8
class Hoge :
@classmethod
def say_hoge(cls) :
print "hoge"