How to test if you're running MacRuby vs. Ruby?
Is there a way to test if code is running in MacRuby rather than Ruby? I'm developing and testing some code using plain old Ruby 1.8.7 in TextMate, then integrating it into an Xcode project, so I need to be able to "comment out" some lines which are Cocoa-dependent when testing in plain Ruby. Paul Howson
def is_macruby? defined? RUBY_ENGINE && RUBY_ENGINE == 'macruby' end Cheers, Josh On Dec 17, 2009, at 12:18 AM, Paul Howson wrote:
Is there a way to test if code is running in MacRuby rather than Ruby? I'm developing and testing some code using plain old Ruby 1.8.7 in TextMate, then integrating it into an Xcode project, so I need to be able to "comment out" some lines which are Cocoa-dependent when testing in plain Ruby.
Paul Howson _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
On 17/12/2009, at 6:21 PM, Josh Ballanco wrote:
def is_macruby? defined? RUBY_ENGINE && RUBY_ENGINE == 'macruby' end
Cheers, Josh
Thanks Josh. However I note this works only if you write: defined?(RUBY_ENGINE) && RUBY_ENGINE == 'macruby' i.e. the argument to defined? must be put in parentheses else MacRuby crashes. Paul Howson
i.e. the argument to defined? must be put in parentheses else MacRuby crashes.
Only because && binds more tightly than method application. It would be nice if some of this code found its way into the Platform gem, or similar. I've found myself writing Kernel#macruby? in libraries a couple of times.
Paul Howson
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Whoops...that's what I get for replying with untested code... On Dec 18, 2009, at 12:14 PM, Paul Howson wrote:
On 17/12/2009, at 6:21 PM, Josh Ballanco wrote:
def is_macruby? defined? RUBY_ENGINE && RUBY_ENGINE == 'macruby' end
Cheers, Josh
Thanks Josh. However I note this works only if you write:
defined?(RUBY_ENGINE) && RUBY_ENGINE == 'macruby'
i.e. the argument to defined? must be put in parentheses else MacRuby crashes.
Paul Howson
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
I use defined? MACRUBY_VERSION, myself. A bit shorter ;) On Fri, Dec 18, 2009 at 3:34 PM, Josh Ballanco <joshua.ballanco@apple.com>wrote:
Whoops...that's what I get for replying with untested code...
On Dec 18, 2009, at 12:14 PM, Paul Howson wrote:
On 17/12/2009, at 6:21 PM, Josh Ballanco wrote:
def is_macruby? defined? RUBY_ENGINE && RUBY_ENGINE == 'macruby' end
Cheers, Josh
Thanks Josh. However I note this works only if you write:
defined?(RUBY_ENGINE) && RUBY_ENGINE == 'macruby'
i.e. the argument to defined? must be put in parentheses else MacRuby crashes.
Paul Howson
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
participants (4)
-
Dylan Bruzenak
-
Jeremy Voorhis
-
Josh Ballanco
-
Paul Howson