Skip to content

Instantly share code, notes, and snippets.

View aereal's full-sized avatar

aereal aereal

View GitHub Profile
def get_each_const(const, context=::Object)
const.to_s.split(/::/).inject(context) {|parent, c|
parent.const_get(c)
}
end
@aereal
aereal / gist:218780
Created October 26, 2009 16:28
Python's 'import' like it
def import(feature, as={})
ret = require feature
self.class.instance_eval do
as.each do |(orig, dest)|
c = const_get(orig)
remove_const(orig) if const_defined?(orig)
const_set(dest, c)
end
end unless as.empty?
ret
#!/usr/bin/env ruby
#
# usage:
# $ git clone git://github.com/motemen/git-vim.git git-vim
# $ ruby vsm.rb git-vim/
VIMDIR = '~/.vim'
SRCDIR = ARGV[0]
require 'pathname'
/* Shell Color */
.bg-std { background-color: rgb( 51, 51, 49) }
.fg-std { color: rgb(230, 230, 230) }
.fg-black { color: rgb( 51, 51, 49) }
.fg-red { color: rgb(255, 51, 60) }
.fg-green { color: rgb( 40, 204, 76) }
.fg-yellow { color: rgb(224, 230, 57) }
.fg-blue { color: rgb( 46, 122, 230) }
hash = {:a => 40, :b => 60, :c => 50, :d => 30}
# #sort_by -> #reverse
hash.sort_by {|k, v| v }.reverse
# => [[:b, 60], [:c, 50], [:a, 40], [:d, 30]]
# #sort_by
hash.sort_by {|k, v| -v }
# => [[:b, 60], [:c, 50], [:a, 40], [:d, 30]]
module Enumerable
def like?(val, op = :===)
any? {|i| i.__send__(op, val) }
end
end
ignore_pattern = [/\.$/, /\.(?:svn|git)$/]
ignore_pattern.include?('..') # => false
ignore_pattern.like?('..') # => true
class Greeting
def hello; end
private do
def bonjour; end
end
protected do
def guten_morgen; end
end
class Integer
def english_name(delimiter='-')
if self < 20
english_table[self]
else
ret = english_table[(self / 10) * 10]
(self % 10) == 0 ? ret : ret + delimiter.to_s + english_table[self % 10]
end
end
class TaniRyoko
def initialize(shout)
@shout = shout
end
def to_s
"#{@shout}! 新谷良子、#{@shout}!!"
end
end
TaniRyoko = "谷良子"
def new(syntanix, shout=nil)
if shout
puts "#{shout}! 新#{syntanix}, #{shout}!!!"
else
puts "New #{syntanix} って…100万回も言われてます。もうあきましたっ!!ばーかばーか。"
end
end