Class: Launchy::Detect::RubyEngine

Inherits:
Object
  • Object
show all
Extended by:
Launchy::DescendantTracker
Defined in:
lib/launchy/detect/ruby_engine.rb

Direct Known Subclasses

Jruby, MacRuby, Mri, Rbx

Defined Under Namespace

Classes: Jruby, MacRuby, Mri, NotFoundError, Rbx

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Launchy::DescendantTracker

children, find_child, inherited

Constructor Details

#initialize(ruby_engine = Launchy.ruby_engine) ⇒ RubyEngine

Returns a new instance of RubyEngine.


40
41
42
43
44
45
46
# File 'lib/launchy/detect/ruby_engine.rb', line 40

def initialize( ruby_engine = Launchy.ruby_engine )
  if ruby_engine then
    @ruby_engine = ruby_engine
  else
    @ruby_engine = defined?( RUBY_ENGINE ) ? RUBY_ENGINE : "ruby"
  end
end

Instance Attribute Details

#ruby_engineObject (readonly) Also known as: to_s

Returns the value of attribute ruby_engine


38
39
40
# File 'lib/launchy/detect/ruby_engine.rb', line 38

def ruby_engine
  @ruby_engine
end

Class Method Details

.detect(ruby_engine = RubyEngine.new) ⇒ Object

Detect the current ruby engine.

If the current ruby engine cannot be detected, the return RubyEngine::Unknown

Raises:


11
12
13
14
15
# File 'lib/launchy/detect/ruby_engine.rb', line 11

def self.detect( ruby_engine = RubyEngine.new )
  found = find_child( :is_current_engine?, ruby_engine.to_s )
  return found if found
  raise NotFoundError, "#{ruby_engine_error_message( ruby_engine )} #{Launchy.bug_report_message}"
end

.is_current_engine?(ruby_engine) ⇒ Boolean

Returns:

  • (Boolean)

29
30
31
# File 'lib/launchy/detect/ruby_engine.rb', line 29

def self.is_current_engine?( ruby_engine )
  return ruby_engine == self.engine_name
end

.jruby?Boolean

Returns:

  • (Boolean)

34
# File 'lib/launchy/detect/ruby_engine.rb', line 34

def self.jruby?()   self == Jruby;   end

.macruby?Boolean

Returns:

  • (Boolean)

36
# File 'lib/launchy/detect/ruby_engine.rb', line 36

def self.macruby?() self == MacRuby; end

.mri?Boolean

Returns:

  • (Boolean)

33
# File 'lib/launchy/detect/ruby_engine.rb', line 33

def self.mri?()     self == Mri;     end

.rbx?Boolean

Returns:

  • (Boolean)

35
# File 'lib/launchy/detect/ruby_engine.rb', line 35

def self.rbx?()     self == Rbx;     end

.ruby_engine_error_message(ruby_engine) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/launchy/detect/ruby_engine.rb', line 17

def self.ruby_engine_error_message( ruby_engine )
  msg = "Unkonwn RUBY_ENGINE "
  if ruby_engine then
    msg += " '#{ruby_engine}'."
  elsif defined?( RUBY_ENGINE ) then
    msg += " '#{RUBY_ENGINE}'."
  else
    msg = "RUBY_ENGINE not defined for #{RUBY_DESCRIPTION}."
  end
  return msg
end