Archive of posts with tag “meta programming”
Labeled
break
,next
, andredo
in RubyMany languages support breaking out of nested loops, such as Perl, Java, JavaScript, C#, etc. Languages that have
goto
can also do this easily. However, in most other languages, it is not easy to break out of nested loops. I want to introduce a way to do this in Ruby.- Categories: programming
- Tags: meta programming, ruby
Writing a DSL with commands split by space
DSL means domain-specific language. Ruby is a powerful script language in terms of building DSLs (as sublanguages of Ruby). In this article, I implemented my idea of a DSL with commands split by space. For example, you may just write
a b c
to run the commandsa
,b
, andc
one after another! This trick is heavily applied in my project alda-rb. How do I achieve this?- Categories: programming
- Tags: ruby, meta programming
Monkey-patching graciously
Monkey-patching is a powerful tool in programming. In this article, I used techniques of Ruby metaprogramming to define a series of methods
def_after
,def_before
, etc. to help monkey-patching. They look graciously in that we can use it to shorten the codes for monkey-patching (avoiding aliasing and repeating codes).- Categories: programming
- Tags: ruby, meta programming, long paper