Skip to content

Instantly share code, notes, and snippets.

@pasberth
Created December 2, 2011 03:26
Show Gist options
  • Select an option

  • Save pasberth/1421596 to your computer and use it in GitHub Desktop.

Select an option

Save pasberth/1421596 to your computer and use it in GitHub Desktop.
前こんなの考えたのを思い出した
# -*- coding: utf-8 -*-
class Module
def define(consname, value=nil, &blk)
if value
const_set(consname, value)
else
define_method(consname, &blk)
end
end
end
Kernel.define :PASBERTH, "パスベルス"
puts PASBERTH
Kernel.define :F do |x|
x*x
end
puts F(5)
module Example
define :CONST
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment