Module: System::Ruby

Defined in:
lib/system/ruby.rb

Overview

Information about the current Ruby interpreter.

Since:

  • 0.1.1

Constant Summary collapse

C =

The C language.

Since:

  • 0.1.3

:c
CPlusPlus =

The C++ language.

Since:

  • 0.1.3

:c_plus_plus
Java =

The Java language.

Since:

  • 0.1.3

:java
MRI =

The Ruby interpreter: MRI.

Since:

  • 0.1.3

:mri
JRuby =

The Ruby interpreter: JRuby.

Since:

  • 0.1.3

:jruby
Rubinius =

The Ruby interpreter: Rubinius.

Since:

  • 0.1.3

:rbx
MagLev =

The Ruby interpreter: MagLev.

Since:

  • 0.1.3

:maglev

Class Method Summary collapse

Class Method Details

Return the current Ruby interpreter’s copyright.

Examples:

System::Ruby.copyright # => "ruby - Copyright (C) 1993-2012 Yukihiro Matsumoto"

Returns:

  • (String)

    The current Ruby interpreter’s copyright.

Since:

  • 0.1.1



# File 'lib/system/ruby.rb', line 41

.copyright?TrueClass, FalseClass

Return if we have information about the copyright.

Examples:

System::Ruby.copyright  # => "ruby - Copyright (C) 1993-2012 Yukihiro Matsumoto"
System::Ruby.copyright? # => true

Returns:

  • (TrueClass, FalseClass)

Since:

  • 0.1.3



# File 'lib/system/ruby.rb', line 49

.descriptionString

Return the current Ruby interpreter’s description which includes the engine, version, release date, revision, and platform.

Examples:

System::Ruby.description # => "ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]"

Returns:

  • (String)

    The current Ruby interpreter’s engine.

Since:

  • 0.1.1



# File 'lib/system/ruby.rb', line 58

.description?TrueClass, FalseClass

Return if we have information about the description.

Examples:

System::Ruby.description  # => "ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]"
System::Ruby.description? # => true

Returns:

  • (TrueClass, FalseClass)

Since:

  • 0.1.3



# File 'lib/system/ruby.rb', line 67

.engineString

Return the current Ruby interpreter’s engine.

Examples:

System::Ruby.engine # => "ruby"

Returns:

  • (String)

    The current Ruby interpreter’s engine.

Since:

  • 0.1.1



# File 'lib/system/ruby.rb', line 76

.engine?TrueClass, FalseClass

Return if we have information about the engine.

Examples:

System::Ruby.engine # => "ruby"
System::Ruby.engine? # => true

Returns:

  • (TrueClass, FalseClass)

Since:

  • 0.1.3



# File 'lib/system/ruby.rb', line 84

.java?TrueClass, FalseClass

Check if Ruby is using Java as it’s base language.

Returns:

  • (TrueClass, FalseClass)

Since:

  • 0.1.1



230
231
232
# File 'lib/system/ruby.rb', line 230

def java?
  language == Java
end

.jruby?TrueClass, FalseClass

Check if Ruby interpreter is JRuby. Delegates to System::Ruby.jruby? for backwards compatibility.

Returns:

  • (TrueClass, FalseClass)

    Is the current Ruby interpreter JRuby?

Since:

  • 0.1.1



247
248
249
# File 'lib/system/ruby.rb', line 247

def jruby?
  java? ? engine =~ /jruby/ : false
end

.languageSymbol

Return the current Ruby interpreter’s base language.

Examples:

On MRI 1.9

System::Ruby.language # => :ruby

On JRuby

System::Ruby.language # => :java

Returns:

  • (Symbol)

    The name of the base language.

Since:

  • 0.1.3



216
217
218
219
220
221
222
223
224
# File 'lib/system/ruby.rb', line 216

def language
  @language ||= if %W[rbx maglev].any? { |name| engine == name }
    CPlusPlus
  elsif platform =~ /java/
    Java
  else
    C
  end
end

.nameSymbol

Return the current Ruby interpreter’s name.

Examples:

Return OS name

System::OS.name # => :osx

Assert current OS

System::OS.name == System::OS::OSX # => true

Returns:

  • (Symbol)

    The name of the operating system.

Since:

  • 0.1.3



196
197
198
199
200
201
202
203
204
205
206
# File 'lib/system/ruby.rb', line 196

def name
  @name ||= if !OS.windows? && ruby?
    MRI
  elsif ruby? && engine? && engine == 'rbx'
    Rubinius
  elsif ruby? && engine? && engine == 'maglev'
    MagLev
  elsif engine? && engine == 'jruby'
    JRuby
  end
end

.patchlevelInteger

Return the current Ruby interpreter’s patch-level.

Examples:

System::Ruby.patchlevel # => 286

Returns:

  • (Integer)

    The current Ruby interpreter’s patch-level.

Since:

  • 0.1.1



# File 'lib/system/ruby.rb', line 93

.patchlevel?TrueClass, FalseClass

Return if we have information about the patchlevel.

Examples:

System::Ruby.patchlevel # => 286
System::Ruby.patchlevel? # => true

Returns:

  • (TrueClass, FalseClass)

Since:

  • 0.1.3



# File 'lib/system/ruby.rb', line 101

.platformString

Return the system platform the current Ruby interpreter is running on.

Examples:

System::Ruby.platform # => "x86_64-darwin12.2.0"

Returns:

  • (String)

    The system platform the current Ruby interpreter is running on.

Since:

  • 0.1.1



# File 'lib/system/ruby.rb', line 110

.platform?TrueClass, FalseClass

Return if we have information about the platform.

Examples:

System::Ruby.platform # => "x86_64-darwin12.2.0"
System::Ruby.platform? # => true

Returns:

  • (TrueClass, FalseClass)

Since:

  • 0.1.3



# File 'lib/system/ruby.rb', line 118

.release_dateString

Return the current Ruby interpreter’s release date.

Examples:

System::Ruby.release_date # => "2012-10-12"

Returns:

  • (String)

    The current Ruby interpreter’s release date.

Since:

  • 0.1.1



# File 'lib/system/ruby.rb', line 144

.release_date?TrueClass, FalseClass

Return if we have information about the release_date.

Examples:

System::Ruby.release_date # => "2012-10-12"
System::Ruby.release_date? # => true

Returns:

  • (TrueClass, FalseClass)

Since:

  • 0.1.3



# File 'lib/system/ruby.rb', line 152

.revisionInteger

Return the current Ruby interpreter’s revision.

Examples:

System::Ruby.revision # => 37165

Returns:

  • (Integer)

    The current Ruby interpreter’s revision.

Since:

  • 0.1.1



# File 'lib/system/ruby.rb', line 127

.revision?TrueClass, FalseClass

Return if we have information about the revision.

Examples:

System::Ruby.revision # => 37165
System::Ruby.revision? # => true

Returns:

  • (TrueClass, FalseClass)

Since:

  • 0.1.3



# File 'lib/system/ruby.rb', line 135

.ruby?TrueClass, FalseClass

Check if Ruby is using C or CPlusPlus as it’s base language.

Returns:

  • (TrueClass, FalseClass)

Since:

  • 0.1.3



238
239
240
# File 'lib/system/ruby.rb', line 238

def ruby?
  [C, CPlusPlus].any? { |language| self.language == language }
end

.versionString

Return the current Ruby interpreter’s version.

Examples:

System::Ruby.version # => "1.9.3"

Returns:

  • (String)

    The current Ruby interpreter’s version.

Since:

  • 0.1.1



# File 'lib/system/ruby.rb', line 161

.version?TrueClass, FalseClass

Return if we have information about the version.

Examples:

System::Ruby.version # => "2012-10-12"
System::Ruby.version? # => true

Returns:

  • (TrueClass, FalseClass)

Since:

  • 0.1.3



178
179
180
181
182
183
184
185
186
# File 'lib/system/ruby.rb', line 178

Object.constants.grep(/^RUBY_/).each do |const_name|
  method_name = const_name.to_s.gsub(/^RUBY_/, '').downcase.to_sym
  
  define_method(method_name) do
    Object.const_defined?(const_name) ? Object.const_get(const_name) : nil
  end
  
  define_method("#{method_name}?") { !send(method_name).nil? }
end