Skip to content

Commit

Permalink
Fix for Ruby 1.9.3 (added a #blank? method)
Browse files Browse the repository at this point in the history
  • Loading branch information
epitron committed Sep 29, 2011
1 parent c375f26 commit 387838a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.1
0.4.3
1 change: 1 addition & 0 deletions lib/delicious-cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
optparse/time
ostruct

delicious-cli/blank
delicious-cli/db
delicious-cli/display
delicious-cli/api
Expand Down
46 changes: 46 additions & 0 deletions lib/delicious-cli/blank.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# Gives all the Ruby base types (String, Hash, nil, etc.) a "blank?" method.
#

class Float
#
# 'true' if the float is 0.0
#
def blank?; self == 0.0; end
end

class NilClass
#
# Always 'true'; nil is considered blank.
#
def blank?; true; end
end

class Symbol
#
# Symbols are never blank.
#
def blank?; false; end
end

class Integer
#
# 'true' if the integer is 0
#
def blank?; self == 0; end
end

class String
#
# 'true' if the string's length is 0 (after whitespace has been stripped from the ends)
#
def blank?; strip.size == 0; end
end

module Enumerable
#
# 'true' if the Enumerable has no elements
#
def blank?; not any?; end
end

0 comments on commit 387838a

Please sign in to comment.