Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Dynamic Languages Toolkit (DLTK) » Ruby dynamically added methods and some static typing
Ruby dynamically added methods and some static typing [message #18131] Sun, 18 November 2007 10:58
Eclipse UserFriend
Originally posted by: martin.thiede.gmx.de

Hello,

currently I am working on a modelling framework for Ruby called RGen
(see Rubyforge if you like), somewhat similar to EMF.
This involves building Ruby classes by means of some kind of Domain
Specific Language. Commands like "has_attr" or "has_one" add setter and
getter methods to the respective class which also ensure that only
values of a certain type can be set:


class Person < RGen::MetamodelBuilder::MMBase
has_attr 'name', String
has_attr 'age', Integer
end

class House < RGen::MetamodelBuilder::MMBase
has_attr 'address', String
end

Person.has_one 'home', House


p = Person.new
p.name = "Martin"
p.name = 5 # this would raise an exception since 5 is not a String

p.home = House.new(:address => "Some street")
p.home = Person.new # this would also raise an exception


It would be really great if DLTK could do two things:

1. show the dynamically added methods for auto completion.

p.<ctrl shift> should provide "name" and "age"

2. derive the result type of an accessor method

p.home.<ctrl shift> should provide "address"
(i.e. DLTK should know that "home" always returns a House)


Regarding 1:

Is there a chance to see dynamically added methods as completion options?

Currently I create the methods using "module_eval", something like:

def self.has_attr(name)
module_eval <<- END
def #{name}
# ...
end
END
end


Regarding 2:

One could define a generic way of giving hints to DLTK regarding method
result types. For example DLTK could check if the method "result_type"
is provided by the object in question. If yes, it could call the method
with the name of the method in question as parameter.

p.result_type(:home) # => House

This way DLTK could derive the result type of method "home" on a Person
object.


Is it technically possible to extend DLTK to enable stuff like this?
If it is and you could give me some hints how to do it I might try to do
so by myself.


Best Regards,

Martin
Previous Topic:Heap error
Next Topic:Semantic Highlighting and ANTLR Parser
Goto Forum:
  


Current Time: Sat Jul 27 11:11:12 GMT 2024

Powered by FUDForum. Page generated in 0.03048 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top