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 Pointer < BasicObject | |
| def initialize value | |
| @value = value | |
| end | |
| def __value__ | |
| @value | |
| 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
| # 文字列から、' ' を除くすべての文字をtrue、 ' ' のみを false に置き換えた二次元配列を作ります。 | |
| # コメントは '__' から始めます。そのあとから行末までのすべての文字は無視されます | |
| # テトリスとかの図形を作る時に使います | |
| module ShapeLang | |
| extend self | |
| # *** // | |
| # * * // | |
| # *** // | |
| # to |
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
| def curryargs(arg=None, args=()): | |
| def _ca(next=None): | |
| return curryargs(next, args + (arg,)) | |
| if arg: | |
| return _ca | |
| else: | |
| return args | |
| def printargs(args): | |
| for arg in args: |
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 Point: | |
| def __init__(self, *vectors): | |
| self.vectors = vectors | |
| def __str__(self): | |
| return str(self.vectors) | |
| def __iter__(self): | |
| return self.vectors.__iter__() |
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
| module Kernel | |
| def funcname | |
| caller[0] =~ /^.*?\:in `(.*?)'$/ | |
| $1.to_sym | |
| end | |
| end | |
| if __FILE__ == $PROGRAM_NAME |
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 -*- | |
| I = [:princess_mana] | |
| def I.get num | |
| at num | |
| end | |
| PRINCESS_MANA = 0 | |
| I.get PRINCESS_MANA # I.first は常にprincess_manaを返さねばなりません。I.first は常にprincess_manaにより予約されています |
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
| module Kernel | |
| def _throw e=RuntimeError, *args, &blk | |
| if e.kind_of? Exception | |
| $! = e | |
| $@ = caller | |
| throw :exception | |
| else | |
| $! = e.new *args, &blk | |
| $@ = caller |
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 -*- | |
| module Kernel | |
| alias m_original_method_missing method_missing | |
| def method_missing funcname, *args, &blk | |
| if funcname.to_s =~ /^(.*?)nnn(.*?)$/ | |
| m_funcname = "#{$1}nn#{$2}" | |
| puts "もしかして: #{m_funcname}" | |
| puts caller |
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 -*- | |
| module Kernel | |
| alias typofixer_original_method_missing method_missing | |
| def method_missing funcname, *args, &blk | |
| at = caller | |
| begin | |
| typofixer_original_method_missing funcname, *args, &blk | |
| rescue NoMethodError, NameError => e |
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
| module Propertible | |
| alias propertible_original_method_missing method_missing | |
| def method_missing funcname, *args, &blk | |
| propertible_original_method_missing funcname, *args, &blk | |
| rescue => e | |
| if funcname.to_s =~ /^(.*)\=$/ | |
| self.class.send :attr_writer, $1 | |
| send :"#{$1}=", args[0] |