This file contains 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
# ary = [0, 1, 2, 3] | |
# ary.shift.foo until ary.empty? | |
# | |
# is equal to: | |
# | |
# ary = [0, 1, 2, 3] | |
# ary.featch { |e| e.foo } | |
class Array |
This file contains 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
# Array#shuffle returns to shuffled self. | |
# Array#shuffle! destructive shuffles to self. | |
# [1, 2, 3, 4, 5].shuffle # => [2, 1, 5, 4, 3] (example) | |
class Array | |
def shuffle | |
clone.shuffle! | |
end |
This file contains 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
# irb(main):001:0> require './closure' | |
# => true | |
# irb(main):002:0> mkclosure 'madohomu' | |
# => nil | |
# irb(main):003:0> homu | |
# madohomu | |
# => nil | |
# irb(main):004:0> mado | |
# NameError: undefined local variable or method `bind' for main:Object |
This file contains 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
# | |
# dict = { "key0": "value0", "key1": "value1", "key2": "value2" } | |
"&".join( [("%s=%s" % (k, v)) for k, v in dict.items()] ) | |
# => 'key2=value2&key1=value1&key0=value0' |
This file contains 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
# h = { "key0"=>"value0", "key1"=>"value1", "key2"=>"value2" } | |
h.map { |k, v| "#{k}=#{v}" }.join('&') | |
# => "key0=value0&key1=value1&key2=value2" |
This file contains 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 -*- | |
# importas は Python で言う import MyClass as RenamedMyClass 的なことをできます | |
# importas Namespace::MyClass, :RenamedMyClass とします | |
def importas(from, to_name) | |
Kernel.const_set(to_name, from) | |
end | |
=begin | |
module Namespace | |
class File; end |
This file contains 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
# [0, 1, 2, 3].car #=> 0, that as (car '(0 1 2 3)) | |
# [0, 1, 2, 3].cdr #=> [1, 2, 3], that as (cdr '(0 1 2 3)) | |
# [0, 1, 2, 3].cdddr #=> [3], that as (cdr (cdr (cdr '(0 1 2 3)))) | |
class Array | |
def car | |
first | |
end |
This file contains 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 String | |
AVAILABLE_CHARS_IN_URI = [ | |
'\;', '\/', '\?', '\:', '\@', '\&', '\=', '\+', '\$', '\,', | |
'\-', '\_', '\.', '\!', '\~', '\*', '\\\'', '\(', '\)', | |
'\%', '0-1', 'a-z', 'A-Z' '\#' | |
] | |
REGEXP_OF_URL = /https?\:\/\/[#{AVAILABLE_CHARS_IN_URI.join('')}]+/ | |
def replace_urls &blk | |
gsub(REGEXP_OF_URL, &blk) |
This file contains 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
(add-to-list 'default-frame-alist '(foreground-color . "rgb:50/50/50")) | |
(add-to-list 'default-frame-alist '(background-color . "rgb:ff/ff/ff")) | |
(set-foreground-color "rgb:50/50/50") | |
(set-background-color "rgb:ff/ff/ff") | |
(set-face-foreground 'font-lock-comment-face "rgb:90/90/80") | |
(set-face-italic-p 'font-lock-comment-face t) | |
(set-face-foreground 'font-lock-string-face "rgb:90/00/00") | |
(set-face-foreground 'font-lock-keyword-face "black") | |
(set-face-bold-p 'font-lock-keyword-face t) | |
(set-face-foreground 'font-lock-function-name-face "rgb:90/00/00") |
This file contains 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 Object | |
def self.define_method(funcname, *params, &blk) | |
@@methods ||= {} | |
@@methods[funcname.to_sym] = blk | |
class_eval(<<DEFINE) | |
def #{funcname} #{params.join(', ')} | |
b = binding | |
def b.method_missing(varname, *args) |
OlderNewer