Top Level Namespace
Defined Under Namespace
Modules: Enumerable, ModalSupport Classes: Array, Hash, NilClass, Object, Pathname, Regexp, String
Instance Method Summary collapse
- #if_ruby_engine_is(engine) ⇒ Object
- #if_ruby_platform_is(platform) ⇒ Object
-
#if_ruby_version(cmp, v) ⇒ Object
Execute code conditinally on Ruby version: if_ruby_version :>=, ‘1.9.2’ do …
- #if_ruby_version_between(v1, v2) ⇒ Object
- #if_ruby_version_between_ex(v1, v2) ⇒ Object
- #ruby_18(&blk) ⇒ Object
- #ruby_19(&blk) ⇒ Object
-
#ruby_engine_is?(engine) ⇒ Boolean
Detect Ruby engine: :ruby, :rbx/:rubinius, :jruby/:java, …
-
#ruby_platform_is?(platform) ⇒ Boolean
detection of some generic platform families * :unix (UN*X systems) with distinguished subfamilies: :linux, :osx/:darwin, :bsd, :cygwin * :windows with variants :mswin32, :mingw32 * :java.
-
#ruby_version?(cmp, v) ⇒ Boolean
Compare the Ruby version with a version string.
-
#ruby_version_between?(v1, v2) ⇒ Boolean
ruby_version_between?(v1,v2) == ruby_version?(:>=,v1) && ruby_version?(:<=,v2).
-
#ruby_version_between_ex?(v1, v2) ⇒ Boolean
ruby_version_between?(v1,v2) == ruby_version?(:>=,v1) && ruby_version?(:<,v2).
Instance Method Details
#if_ruby_engine_is(engine) ⇒ Object
9 10 11 |
# File 'lib/modalsupport/ruby_engine.rb', line 9 def if_ruby_engine_is(engine) yield if ruby_engine_is?(engine) end |
#if_ruby_platform_is(platform) ⇒ Object
31 32 33 |
# File 'lib/modalsupport/ruby_platform.rb', line 31 def if_ruby_platform_is(platform) yield if platform_is?(platform) end |
#if_ruby_version(cmp, v) ⇒ Object
Execute code conditinally on Ruby version:
if_ruby_version :>=, '1.9.2' do
...
end
33 34 35 |
# File 'lib/modalsupport/ruby_version.rb', line 33 def if_ruby_version(cmp, v) yield if ruby_version?(cmp, v) end |
#if_ruby_version_between(v1, v2) ⇒ Object
37 38 39 |
# File 'lib/modalsupport/ruby_version.rb', line 37 def if_ruby_version_between(v1, v2) yield if ruby_version_between?(v1, v2) end |
#if_ruby_version_between_ex(v1, v2) ⇒ Object
41 42 43 |
# File 'lib/modalsupport/ruby_version.rb', line 41 def if_ruby_version_between_ex(v1, v2) yield if ruby_version_between_ex?(v1, v2) end |
#ruby_18(&blk) ⇒ Object
49 50 51 |
# File 'lib/modalsupport/ruby_version.rb', line 49 def ruby_18(&blk) if_ruby_version :'~>', '1.8.0', &blk end |
#ruby_19(&blk) ⇒ Object
45 46 47 |
# File 'lib/modalsupport/ruby_version.rb', line 45 def ruby_19(&blk) if_ruby_version :'~>', '1.9.0', &blk end |
#ruby_engine_is?(engine) ⇒ Boolean
Detect Ruby engine: :ruby, :rbx/:rubinius, :jruby/:java, …
3 4 5 6 7 |
# File 'lib/modalsupport/ruby_engine.rb', line 3 def ruby_engine_is?(engine) # "ruby" "jruby" "rbx" engine = {:rubinius=>:rbx, :java=>:jruby}[engine] || engine current_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby' engine.to_s == current_engine end |
#ruby_platform_is?(platform) ⇒ Boolean
detection of some generic platform families
-
:unix (UN*X systems) with distinguished subfamilies: :linux, :osx/:darwin, :bsd, :cygwin
-
:windows with variants :mswin32, :mingw32
-
:java
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/modalsupport/ruby_platform.rb', line 5 def ruby_platform_is?(platform) ruby_platform = ruby_version?(:<,'1.9.0') ? PLATFORM : RUBY_PLATFORM case platform when :unix ruby_platform =~ /linux|darwin|freebsd|netbsd|solaris|aix|hpux|cygwin/ when :linux ruby_platform =~ /linux/ when :osx, :darwin ruby_platform =~ /darwin/ when :bsd ruby_platform =~ /freebsd|netbsd/ when :cygwin ruby_platform =~ /cygwin/ when :windows ruby_platform =~ /mswin32|mingw32/ when :mswin32 ruby_platform =~ /mswin32/ when :mingw32 ruby_platform =~ /mingw32/ when :java ruby_platform =~ /java/ else raise RuntimeError, "Invalid platform specifier" end ? true : false end |
#ruby_version?(cmp, v) ⇒ Boolean
Compare the Ruby version with a version string
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/modalsupport/ruby_version.rb', line 8 def ruby_version?(cmp, v) rv = Gem::Version.create(RUBY_VERSION.dup) v = Gem::Version.create(v) if cmp.to_sym==:'~>' rv = rv.release rv >= v && rv < v.bump else rv.send(cmp,v) end end |
#ruby_version_between?(v1, v2) ⇒ Boolean
ruby_version_between?(v1,v2) == ruby_version?(:>=,v1) && ruby_version?(:<=,v2)
20 21 22 |
# File 'lib/modalsupport/ruby_version.rb', line 20 def ruby_version_between?(v1, v2) (Gem::Version.create(v1)..Gem::Version.create(v2)).include?(Gem::Version.create(RUBY_VERSION)) end |
#ruby_version_between_ex?(v1, v2) ⇒ Boolean
ruby_version_between?(v1,v2) == ruby_version?(:>=,v1) && ruby_version?(:<,v2)
25 26 27 |
# File 'lib/modalsupport/ruby_version.rb', line 25 def ruby_version_between_ex?(v1, v2) (Gem::Version.create(v1).-.Gem::Version.create(v2)).include?(Gem::Version.create(RUBY_VERSION)) end |