Hi, I remember Tomas has posted a code review about IsRubyMethod some time ago. I was looking for it in the code but i couldn''t find it. Is it still there? Thanks, Shay. ---------------------------- Shay Friedman http://www.ironshay.com Follow me: http://twitter.com/ironshay -- Posted via http://www.ruby-forum.com/.
Shay Friedman wrote:> I remember Tomas has posted a code review about IsRubyMethod some time > ago. > I was looking for it in the code but i couldn''t find it. Is it still > there?Shay, I couldn''t find it in the source either (unless it is called something else) In the meantime, perhaps we could come up with a method that does something similar that will meet your needs.. What are you trying to accomplish? -- Posted via http://www.ruby-forum.com/.
I guess this could be one way to do it
class Class
def ruby_method?(name)
begin
self.class.clr_member name.to_sym
return false
rescue
return true
end
end
end
or something along those lines. I have a thing against relying on exceptions
for these kinds of methods but that will work.
Exceptions are meant for exceptional cases and this isn''t an
exceptional
case :)
You could also check if the type is a clr type and if it is enumerate the
clr methods with reflection something like this
class String
# converts a camel cased word to an underscored word
def underscore
self.gsub(/::/, ''/'').
gsub(/([A-Z]+)([A-Z][a-z])/,''\1_\2'').
gsub(/([a-z\d])([A-Z])/,''\1_\2'').
tr("-", "_").
downcase
end
end
if ctype = MyClass.to_clr_type
members = ctype.get_methods + ctype.get_properties
!members.collect { |mem| mem.to_s.underscore }.include? :my_method
else
return true
end
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
On Tue, Jul 14, 2009 at 5:46 PM, Kevin Radcliffe <lists at
ruby-forum.com>wrote:
> Shay Friedman wrote:
> > I remember Tomas has posted a code review about IsRubyMethod some time
> > ago.
> > I was looking for it in the code but i couldn''t find it. Is
it still
> > there?
>
> Shay, I couldn''t find it in the source either (unless it is called
> something else)
> In the meantime, perhaps we could come up with a method that does
> something similar that will meet your needs..
> What are you trying to accomplish?
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/ironruby-core/attachments/20090714/3833327b/attachment.html>
I thought it would be a smooth way of figuring out whether a method is a pure Ruby one or a CLR one. I found the post I was talking about (look at the last paragraph): http://www.ruby-forum.com/topic/189940 I guess it was removed somewhere along the way. Thanks! Shay. ---------------------------- Shay Friedman http://www.ironshay.com Follow me: http://twitter.com/ironshay -- Posted via http://www.ruby-forum.com/.
It''s called IsRubyMember now and it''s an internal property on RubyMemberInfo. Would it help to expose it on Method and UnboundMethod? It could be called e.g. "clr_member?". What would be the use case for such a method? Tomas -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Shay Friedman Sent: Tuesday, July 14, 2009 1:33 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IsRubyMethod I thought it would be a smooth way of figuring out whether a method is a pure Ruby one or a CLR one. I found the post I was talking about (look at the last paragraph): http://www.ruby-forum.com/topic/189940 I guess it was removed somewhere along the way. Thanks! Shay. ---------------------------- Shay Friedman http://www.ironshay.com Follow me: http://twitter.com/ironshay -- Posted via http://www.ruby-forum.com/. _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core