postmodern / chruby

Changes the current Ruby
MIT License
2.86k stars 190 forks source link

support mruby with no `defined?` method #328

Closed kbrock closed 9 years ago

kbrock commented 9 years ago

Hi,

mruby does not provide defined? and it looks like it won't mruby/mruby#1696 As of Mar 21, 2015, mruby-dev does no support const_defined? or defined?.

How about using rescue instead of defined? to determine RUBY_ENGINE. EDIT: How about using Object.const_defined? to determine RUBY_ENGINE

Thanks --K

cremno commented 9 years ago

Um, but Object.const_defined?(:RUBY_ENGINE) works as expected?

brettrann commented 9 years ago

https://github.com/mruby/mruby/issues/1696#issuecomment-34826066

In the referenced ticket, it is recommended to use const_defined? over defined? rather than saying const_defined? does not work.

kbrock commented 9 years ago

@cremno thanks. I was trying the non symbol form Object.const_defined?(RUBY_ENGINE)

This works for both mruby and mri 2.0.

Will reformat. this is great

cremno commented 9 years ago

I see. But now you've introduced a typo (RUBY_ENINE).

kbrock commented 9 years ago

Thanks @cremno

havenwood commented 9 years ago

This looks good to me. Should it be Module.const_defined?(:RUBY_ENGINE) though?

cremno commented 9 years ago

I prefer Object since RUBY_ENGINE (and global constants in general) is defined on it.