This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
web: bundle exec rackup config.ru -p $PORT | |
hello: echo "Hello, world" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env rvm 2.0.0 do ruby | |
# coding: utf-8 | |
p $; | |
#=> nil | |
p 'hoge fuga homu '.split(nil) | |
#=> ["hoge", "fuga", "homu"] | |
p $; = /\t/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# coding: utf-8 | |
class Fixnum | |
define_method "+-" do |other| | |
self-other .. self+other | |
end | |
end | |
p 3.send("+-", 3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
class Hoge | |
module DefaultConstants | |
FUGA = 3 | |
HOMU = 4 | |
end | |
include DefaultConstants | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env rvm 2.0.0 do ruby | |
def hoge(h, o) | |
p [h, o] | |
end | |
def fuga(h: 1, o: 1) | |
p [h, o] | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# coding: utf-8 | |
def parse_attr(params) | |
Hash[params.map{|_|_.split(":").zip([:to_sym, :to_s]).map{|_,__|[_,__].inject(:send)}}] | |
end | |
params = ['rake:app', 'hoge:fuga'] | |
p parse_attr(params) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# coding: utf-8 | |
class Object | |
def idempotent | |
self | |
end | |
end | |
str = "hoge" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hoge | |
def to_s | |
inspect | |
end | |
end | |
p Hoge.new | |
#=> stack level too deep (SystemStackError) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# coding: utf-8 | |
require "nokogiri" | |
document = Nokogiri::XML::Builder.new do |doc| | |
doc.RootNode { | |
doc.ChildElement.hoge.fuga!.pero "Text in ChildElement" | |
doc.SecondChildElement(class: 'hoge', id: 'fuga') | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# coding: utf-8 | |
class String | |
def invert | |
return self unless self.split(//).uniq.length == 2 | |
str = self | |
a, b = str.split(//).uniq | |
tmp = ([*"a".."z"] - [a, b]).first |