Skip to content

Instantly share code, notes, and snippets.

View murajun1978's full-sized avatar
๐ŸŒธ

murajun1978 murajun1978

๐ŸŒธ
  • GEEX
  • Japan
View GitHub Profile
module Foo
def foo
:foo
end
end
class Bar
include Foo
def bar
class String
def to_s
"murajun1978"
end
end
"Ruby".to_s # => "murajun1978"
module Murajun
class String
def to_s
"murajun1978"
end
end
end
"Ruby".to_s # => "Ruby"
Murajun::String.new.to_s # => "murajun1978"
class Foo
private_class_method def self.common_method(*syms)
syms.each do |sym|
define_method sym do
puts sym
end
end
end
common_method :murajun, :murajun1978
[1, 2, 3].select {|n| n == 2} # => [2]
[1, 2, 3].select &2.method(:==) # => [2]
class Enemy
def initialize
@enemies = {}
end
def method_missing(method_name, *args)
enemy = method_name.to_s
if enemy =~ /=\z/
@enemies[enemy.chop] = args[0]
else
class Foo
def bar
:bar
end
def baz
:baz
end
end
anonymous_class = Class.new(String) do
def hello(name)
"Hello, #{name}"
end
end
ex_class = anonymous_class.new
p ex_class.hello("murajun1978") # => murajun1978
class Murajun
def initialize(name)
@name = name
end
def murajun?
@name == "murajun"
end
end
box: inwy/[email protected]
services:
- wercker/postgresql
build:
steps:
- bundle-install
- rails-database-yml:
service: postgresql
- script:
name: echo ruby information