15
Jan
10

from Ruby to Fantom:introspection


Hopefully, you know about the Fantom programming language. It’s an extraordinary language I discovered about 4 days ago. I’m hooked on it. It looks so very similar to Ruby, it’s lightning fast, and you have a lot of fun writing it. Oh … by the way, it’s a mix of static-dynamic typing, so you get compile-time checking. How great is that ?

Anyway, enough with the introduction. Let’s get to the good part:

Let’s assume this Ruby code:


a = "geo,blog"

Sometimes, in the “wild”, you don’t have access to certain object’s docs. Many languages have introspection mechanisms. Ruby and Fantom are two of them. I know that in this case,a is a String, and we kinda know what it’s methods are … but what would we do if we didn’t? Here’s what:


methods = a.methods
methods.each {|m| puts m}

and this will print all of that object’s methods.

Here’s how we’d do the same thing in Fantom:


a := "geo,blog"
Type.of(a).methods.each |m| { echo(m) }

Advertisements

0 Responses to “from Ruby to Fantom:introspection”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Blog Stats

  • 223,800 hits

%d bloggers like this: