Ruby.rewrite(Ruby)
In this RubyFringe talk, Reginald Braithwaite writes Ruby code to read, write, and rewrite Ruby. Demos include extending Ruby with conditional expressions, call-by-name and more.
- Ruby,
Tracking change and innovation in the enterprise software development community
Posted by Werner Schuster on Feb 14, 2008 03:00 PM
With the introduction of LINQ in .NET and the resurging interest in LISP, a certain type of metaprogramming has received renewed attention. In LINQ, it's possible to get the Expression Trees, i.e. a tree based representation, of a piece of code.LDAP::User.select { |m| m.name == 'jon' && m.age == 21 }
Or
SQL::User.select { |m| m.name == 'jon' && m.age == 21 }
The code inside these Blocks is never actually executed - instead ParseTree is used to get at the AST. This is then analyzed and translated into queries for the target query language. Ambition features extensible adapters, which allow to write new translators from Ruby ASTs to query languages. old_nonruby_posts = posts.filter {:stamp > 1.month.ago && :category != 'ruby'}
It's important to note that, unlike Ambition, this is just one of Sequel's ways of writing queries - it also allows to put the queries in string literals. Parameterized Actions:
If you specify parameters in your action methods, incoming query parameters will automatically get assigned as appropriate. Some examples:
class Foos < Merb::Controller
def index(id, search_string = "%")
@foo = Foo.find_with_search(id, search_string)
end
end
Going to /foos/index/12 will call the index method with the parameters "12" and "%" (the default provided). Going to /foos/index will throw a BadBehavior error (status code 400) because id is a required parameter, but it was not passed in. Going to /foos/index/5?search_string=hello will call the index method with parameters "5" and "hello". The bottom line is that you get to use your actions like real methods.The feature is implemented by looking getting the AST of the method that handles the action, and extracting the default arguments. In a way, this allows a kind of introspection/reflection that's not normally available.
require 'ripper'This can then be used as such:
class MyRipper < Ripper
def on_gvar(node)
puts node
end
def on_int(node)
puts node
end
# etc.
# Handle each element of the AST with an on_* method
end
f = MyRipper.new("$foo = 1")
f.parse
Next to Ruby 1.9 support, ParseTree also has varying support on alternative Ruby implementations. Rubinius makes heavy use of ParseTree AST representation. JRuby has a nearly complete port of ParseTree, but the .NET based Ruby implementations seem to be without support for now.
Continuous Application Performance eKit - Articles, Discussion Panel, Whitepapers, Demos
Webcast: Applying lean thinking to the governance of software development
Agile Projects: Five Ways to Fail When You Scale
Another use of ParseTree:
www.artweb-design.de/2008/2/17/sending-ruby-to-...
Basically this allows to jail code in Haml templates.
In this RubyFringe talk, Reginald Braithwaite writes Ruby code to read, write, and rewrite Ruby. Demos include extending Ruby with conditional expressions, call-by-name and more.
Aptana RadRails: An IDE for Rails Development by Javier Ramírez discusses the latest Aptana RadRails IDE, a development environment for creating Ruby on Rails applications.
Cliff Click discusses how to optimize generated bytecode for running on the JVM. Click analyzes and reports on several JVM languages and shows several places where they could increase performance.
Scott Ambler, Practice Lead for Agile Development at IBM, speaks on the current status of the Agile community and practices having a look at the perspective of the Agile’s future.
Dave Nicolette and Karl Scotland try to introduce non-technical managers to one of the most popular Agile development techniques: Test-Driven Development (TDD).
Smooks is best known for its transformation capabilities, but in this article Tom Fennelly describes how you can also use it for structured event streaming.
Successful architectures evolve over time to meet changing business requirements. Luke Hohmann presents how to collaborate with key members of your business to manage architectural changes.
In this article, Dr. Tobias Komischke explains how colors used in a GUI can influence our interaction with a computer and offers advice on using the appropriate colors for the interface.
1 comment
Reply