Skip to content

Instantly share code, notes, and snippets.

View murajun1978's full-sized avatar
🌸

murajun1978 murajun1978

🌸
  • GEEX
  • Japan
View GitHub Profile
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 Foo
def bar
:bar
end
def baz
:baz
end
end
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
[1, 2, 3].select {|n| n == 2} # => [2]
[1, 2, 3].select &2.method(:==) # => [2]
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
module Murajun
class String
def to_s
"murajun1978"
end
end
end
"Ruby".to_s # => "Ruby"
Murajun::String.new.to_s # => "murajun1978"
class String
def to_s
"murajun1978"
end
end
"Ruby".to_s # => "murajun1978"
module Foo
def foo
:foo
end
end
class Bar
include Foo
def bar
@murajun1978
murajun1978 / ruby_silver_array.rb
Created May 1, 2014 09:07
Rubyの配列 (Ruby Silver)
ary = Array.new(2, Hash.new)
ary =[0][:dog] = "pochi"
ary #=> ???
ary = Array.new(2){Hash.new}
ary[0][:dog] = "pochi"
ary #=> ???
@murajun1978
murajun1978 / ボーリングのスコア計算
Created April 26, 2014 05:07
Shinosaka.rb ペアプロ問題
ex.
[[5,3],[7,2],[8,/],[X],[7,1],[9,-],[6,2],[X],[6,/],[8,-]]
score: 126
[]: 1フレーム
n: 倒したピンの数
X: ストライク
/: スペア
-: ガター