Monday, April 7, 2008

Video Kucing Diblok Mohamad Nuh

Beginilah sekarang penampakan dari blog salah seorang teman, penuh dengan blank spaces.

Jadi ingat Republik Idiot-nya RMS.

Tuesday, April 1, 2008

Symbolic Mode chmod Support

I put my implementation of symbolic mode support for ruby's chmod on id-ruby's googlecode svn repository. This uses Regexp#global_match in my previous post, and handles all symbolic mode chmod cases. Enjoy.

Global Match for Ruby

An equivalence of Perl regular expression's /g (global match) modifier. If this doesn't make sense to you, please read perlretut manpage.

class Regexp
def global_match(str, &proc)
retval = nil
loop do
res = str.sub(self) do |m|$~) # pass MatchData obj
break retval if res == str
str = res
retval ||= true

and the cat dog house example from perlretut rewritten:

re = /(\w+)/
words = []
re.global_match("cat dog house") do |m|
p words # ["cat", "dog", "house"]