Skip to content

Instantly share code, notes, and snippets.

@osyo-manga
osyo-manga / test.rb
Created January 19, 2016 12:21
test.rb
require "stitcher"
using Stitcher
class Super
stitcher_require [Fixnum]
def func a
p "Fixnum"
end
end
require "stitcher"
using Stitcher
class Array
stitcher_require +[Fixnum, Fixnum]
def at *indices
at(indices.shift).at(*indices)
end
end
@osyo-manga
osyo-manga / main.rb
Last active January 13, 2016 16:08
momonga
class Object
def _
self_ = self
Class.new(BasicObject) do
define_singleton_method(:method_missing) do |name, *args, &block|
return self_.__send__(name, *args, &block) unless block && block.parameters.size == 0
self_.__send__(name, *args) do |*args|
Object.new.instance_eval do
define_singleton_method(:_) { args[0] }
args.size.times do |i|
module Hoge
def hoge_method
end
refine Class do
def class_ex
end
end
module ExImpl
def homu
p "homu"
end
end
module Ex
refine Module do
include ExImpl
module Homu
def homu
# Error: `homu': undefined local variable or method `mami' for X:Class (NameError)
mami
end
def mami
p :mami
end
end
@osyo-manga
osyo-manga / define.rb
Created December 13, 2015 06:57
define
class X
extend Define
plus(a: Fixnum, b: Fixnum){
a + b
}
plus(a: String, b: String){
"#{a}:#{b}"
}
module M
def hoge
end
def foo
hoge
end
end
@osyo-manga
osyo-manga / test2.rb
Created November 26, 2015 02:43
momonga
module ArrayEx
refine Array do
def === other
each_with_index do |it, index|
return false unless it === other[index]
end
true
end
end
end
@osyo-manga
osyo-manga / main.rb
Created November 24, 2015 04:56
call_one
def call_one &block
result = nil
proc { |*args| result ||= instance_exec(*args, &block) }
end
twice = call_one { |a| a + a }
p twice.call "homu"
p twice.call "mami"