From 1f32f89ae6d406e12db9cd1645e5eca31452b465 Mon Sep 17 00:00:00 2001 From: r-obert Date: Sun, 22 Oct 2017 17:07:47 +0200 Subject: add linux? & mac_osx? predicates to BaseHelpers (#1668) * add linux? and mac_osx? predicates to BaseHelpers * update documentation --- CHANGELOG.md | 7 +++++++ lib/pry/helpers/base_helpers.rb | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff1776d0..e10174f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +### HEAD + +__Features:__ + +* Add mac_osx? and linux? utility functions to Pry::Helpers::BaseHelpers. +[#1668](https://github.com/pry/pry/pull/1668) + ### 0.11.0 * Add alias 'whereami[?!]+' for 'whereami' command. ([#1597](https://github.com/pry/pry/pull/1597)) diff --git a/lib/pry/helpers/base_helpers.rb b/lib/pry/helpers/base_helpers.rb index 0b6cc560..cb5eac92 100644 --- a/lib/pry/helpers/base_helpers.rb +++ b/lib/pry/helpers/base_helpers.rb @@ -60,9 +60,38 @@ class Pry "\e[1m#{text}\e[0m" end - # have fun on the Windows platform. + # + # @return [Boolean] + # Returns true if Pry is running on Mac OSX. + # + # @note + # Queries RbConfig::CONFIG['host_os'] with a best guess. + # + def mac_osx? + !!(RbConfig::CONFIG['host_os'] =~ /\Adarwin/i) + end + + # + # @return [Boolean] + # Returns true if Pry is running on Linux. + # + # @note + # Queries RbConfig::CONFIG['host_os'] with a best guess. + # + # + def linux? + !!(RbConfig::CONFIG['host_os'] =~ /linux/i) + end + + # + # @return [Boolean] + # Returns true if Pry is running on Windows. + # + # @note + # Queries RbConfig::CONFIG['host_os'] with a best guess. + # def windows? - RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ + !!(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/) end # are we able to use ansi on windows? -- cgit v1.2.1