ruby-rails-extensions 1.1.1 → 2.0.0.pre.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/lib/ruby-rails-extensions/extensions/all_keys.rb +3 -5
  4. data/lib/ruby-rails-extensions/extensions/all_values.rb +3 -5
  5. data/lib/ruby-rails-extensions/extensions/any_key.rb +3 -5
  6. data/lib/ruby-rails-extensions/extensions/any_value.rb +3 -5
  7. data/lib/ruby-rails-extensions/extensions/assign_nil.rb +51 -56
  8. data/lib/ruby-rails-extensions/extensions/clean_string.rb +22 -30
  9. data/lib/ruby-rails-extensions/extensions/compact_blank_join.rb +6 -8
  10. data/lib/ruby-rails-extensions/extensions/compact_map.rb +11 -15
  11. data/lib/ruby-rails-extensions/extensions/current_day.rb +3 -5
  12. data/lib/ruby-rails-extensions/extensions/current_month.rb +6 -10
  13. data/lib/ruby-rails-extensions/extensions/current_week.rb +6 -10
  14. data/lib/ruby-rails-extensions/extensions/day_of_week.rb +6 -10
  15. data/lib/ruby-rails-extensions/extensions/display_military.rb +6 -10
  16. data/lib/ruby-rails-extensions/extensions/display_user.rb +9 -15
  17. data/lib/ruby-rails-extensions/extensions/find_bang.rb +7 -11
  18. data/lib/ruby-rails-extensions/extensions/find_dupes.rb +8 -10
  19. data/lib/ruby-rails-extensions/extensions/first_dupe.rb +4 -6
  20. data/lib/ruby-rails-extensions/extensions/google_format.rb +3 -5
  21. data/lib/ruby-rails-extensions/extensions/hash_only.rb +16 -20
  22. data/lib/ruby-rails-extensions/extensions/humanize_symbol.rb +2 -4
  23. data/lib/ruby-rails-extensions/extensions/in_utc.rb +6 -10
  24. data/lib/ruby-rails-extensions/extensions/input.rb +6 -10
  25. data/lib/ruby-rails-extensions/extensions/month_and_year.rb +3 -5
  26. data/lib/ruby-rails-extensions/extensions/month_year.rb +3 -5
  27. data/lib/ruby-rails-extensions/extensions/no_keys.rb +3 -5
  28. data/lib/ruby-rails-extensions/extensions/no_values.rb +3 -5
  29. data/lib/ruby-rails-extensions/extensions/only_some.rb +16 -18
  30. data/lib/ruby-rails-extensions/extensions/overlaps.rb +5 -9
  31. data/lib/ruby-rails-extensions/extensions/pipe.rb +1 -5
  32. data/lib/ruby-rails-extensions/extensions/presence_bang.rb +9 -11
  33. data/lib/ruby-rails-extensions/extensions/quarter_dates.rb +28 -34
  34. data/lib/ruby-rails-extensions/extensions/range_add.rb +36 -38
  35. data/lib/ruby-rails-extensions/extensions/range_multiply.rb +36 -38
  36. data/lib/ruby-rails-extensions/extensions/remove_reserved_keywords.rb +18 -20
  37. data/lib/ruby-rails-extensions/extensions/safe_parse.rb +15 -21
  38. data/lib/ruby-rails-extensions/extensions/select_present.rb +0 -4
  39. data/lib/ruby-rails-extensions/extensions/select_present_join.rb +1 -3
  40. data/lib/ruby-rails-extensions/extensions/set_to_sentence.rb +2 -4
  41. data/lib/ruby-rails-extensions/extensions/to_bool.rb +14 -24
  42. data/lib/ruby-rails-extensions/extensions/to_dec.rb +9 -15
  43. data/lib/ruby-rails-extensions/extensions/to_i.rb +6 -10
  44. data/lib/ruby-rails-extensions/extensions/to_local.rb +8 -12
  45. data/lib/ruby-rails-extensions/extensions/to_negative_i.rb +22 -28
  46. data/lib/ruby-rails-extensions/extensions/to_nonzero_i.rb +22 -28
  47. data/lib/ruby-rails-extensions/extensions/to_or_sentence.rb +5 -9
  48. data/lib/ruby-rails-extensions/extensions/to_positive_i.rb +22 -28
  49. data/lib/ruby-rails-extensions/extensions/to_sort_i.rb +1 -7
  50. data/lib/ruby-rails-extensions/extensions/to_x.rb +9 -15
  51. data/lib/ruby-rails-extensions/extensions/todays_date.rb +9 -12
  52. data/lib/ruby-rails-extensions/extensions/uniq_map.rb +13 -15
  53. data/lib/ruby-rails-extensions/extensions/usd_to_f.rb +9 -15
  54. data/lib/ruby-rails-extensions/extensions/usd_to_i.rb +6 -10
  55. data/lib/ruby-rails-extensions/extensions/weighted_sum.rb +16 -18
  56. data/lib/ruby-rails-extensions/extensions/yesno.rb +9 -15
  57. data/lib/ruby-rails-extensions/extensions/zero_range.rb +14 -16
  58. data/lib/ruby-rails-extensions/version.rb +1 -1
  59. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e8f9814c953c52a6b56ec84e47dcb454cfab59a93b0df09b9ab13c4316dde06
4
- data.tar.gz: a048a5ade66c437bd04dabd3b144d91c60db8fc9743df5844731c7623ee8016a
3
+ metadata.gz: 1048be3864dabbae6b8f4c583b882f8d1733359925459d1038ebeb55496be69d
4
+ data.tar.gz: 19b81681e64e638ea6cd13b5f7eab494791ba80684485ad5c463c5a6e70ea7f0
5
5
  SHA512:
6
- metadata.gz: b3cbde7896d269f925aa33a25be9e7d9819a2ef351a4681b56f3afc1794c8e5d6c8e4104fd7b0570c9cd0ed3e30dcb2e1722442edb3b3322e031022500dd25ee
7
- data.tar.gz: 74694442b83d70c7c7562838879014ecee55a5e9b66392be54414c20f1c6f7457375f9907ae11c2cc9a0787836deaa618c3ccc444516c50678abc53626915245
6
+ metadata.gz: d652662723e9c0fde85697a30a06f8cdc856d737f6aae161adbca99a108244d79c5f13992521bf1e56e673e0142d18fcfd42470c9a3391221f04655df7674ac4
7
+ data.tar.gz: 92a67c99eca9ebd748ce097002469e8089a203b8bb696748c1a59ad06425d74173a7f5aa1bef4069812fbfd4b96b4ede447040b4957603a5d3669b2ba9a456b9
data/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
  Unreleased Changes
2
2
  ------------------
3
3
 
4
+ 2.0.0 (2024-07-26)
5
+ ------------------
6
+
7
+ * Possible breaking change:
8
+ * The check for `method_defined?` was removed because the whole point of this gem is to define the methonds in that
9
+ block. This means there are some things assumed the developer using this gem already has, from this gem or rails,
10
+ e.g. `Enumerable#compact_blank_join` relies on `Enumerable#compact_blank`
11
+
4
12
  1.1.1 (2024-03-01)
5
13
  ------------------
6
14
 
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Hash.class_eval do
4
- unless method_defined?(:all_keys?)
5
- # @see Enumerable#all?
6
- def all_keys?(...)
7
- keys.all?(...)
8
- end
4
+ # @see Enumerable#all?
5
+ def all_keys?(...)
6
+ keys.all?(...)
9
7
  end
10
8
  end
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Hash.class_eval do
4
- unless method_defined?(:all_values?)
5
- # @see Enumerable#all?
6
- def all_values?(...)
7
- values.all?(...)
8
- end
4
+ # @see Enumerable#all?
5
+ def all_values?(...)
6
+ values.all?(...)
9
7
  end
10
8
  end
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Hash.class_eval do
4
- unless method_defined?(:any_key?)
5
- # @see Enumerable#any?
6
- def any_key?(...)
7
- keys.any?(...)
8
- end
4
+ # @see Enumerable#any?
5
+ def any_key?(...)
6
+ keys.any?(...)
9
7
  end
10
8
  end
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Hash.class_eval do
4
- unless method_defined?(:any_value?)
5
- # @see Enumerable#any?
6
- def any_value?(...)
7
- values.any?(...)
8
- end
4
+ # @see Enumerable#any?
5
+ def any_value?(...)
6
+ values.any?(...)
9
7
  end
10
8
  end
@@ -1,67 +1,62 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- if defined?(ActiveModel::AttributeAssignment) && Hash.method_defined?(:stringify_keys)
4
- module ActiveModel
5
- module AttributeAssignment
6
- unless method_defined?(:assign_nil_attributes)
7
- # Allows you to set nil attributes by passing in a hash of attributes with
8
- # keys matching the attribute names.
9
- #
10
- # @raise [ActiveModel::ForbiddenAttributesError] If the passed hash responds to `permitted?` method
11
- # and the return value of this method is +false+.
12
- #
13
- # @example
14
- #
15
- # class Cat
16
- # include ActiveModel::AttributeAssignment
17
- # attr_accessor :name, :status
18
- # end
19
- #
20
- # cat = Cat.new
21
- # cat.assign_nil_attributes(name: "Gorby")
22
- # cat.name # => 'Gorby'
23
- # cat.status # => nil
24
- # cat.assign_nil_attributes(status: "yawning")
25
- # cat.name # => 'Gorby'
26
- # cat.status # => 'yawning'
27
- # cat.assign_nil_attributes(status: "sleeping")
28
- # cat.name # => 'Gorby'
29
- # cat.status # => 'yawning'
30
- #
31
- # @param new_attributes
32
- #
33
- # @return [void]
34
- #
35
- def assign_nil_attributes(new_attributes)
36
- unless new_attributes.respond_to?(:stringify_keys)
37
- raise(ArgumentError, 'When assigning attributes, you must pass a hash as an argument.')
38
- end
3
+ # requires `ActiveModel::AttributeAssignment` and `Hash#stringify_keys`
4
+ module ActiveModel
5
+ module AttributeAssignment
6
+ # Allows you to set nil attributes by passing in a hash of attributes with
7
+ # keys matching the attribute names.
8
+ #
9
+ # @raise [ActiveModel::ForbiddenAttributesError] If the passed hash responds to `permitted?` method
10
+ # and the return value of this method is +false+.
11
+ #
12
+ # @example
13
+ #
14
+ # class Cat
15
+ # include ActiveModel::AttributeAssignment
16
+ # attr_accessor :name, :status
17
+ # end
18
+ #
19
+ # cat = Cat.new
20
+ # cat.assign_nil_attributes(name: "Gorby")
21
+ # cat.name # => 'Gorby'
22
+ # cat.status # => nil
23
+ # cat.assign_nil_attributes(status: "yawning")
24
+ # cat.name # => 'Gorby'
25
+ # cat.status # => 'yawning'
26
+ # cat.assign_nil_attributes(status: "sleeping")
27
+ # cat.name # => 'Gorby'
28
+ # cat.status # => 'yawning'
29
+ #
30
+ # @param new_attributes
31
+ #
32
+ # @return [void]
33
+ #
34
+ def assign_nil_attributes(new_attributes)
35
+ unless new_attributes.respond_to?(:stringify_keys)
36
+ raise(ArgumentError, 'When assigning attributes, you must pass a hash as an argument.')
37
+ end
39
38
 
40
- return if new_attributes.empty?
39
+ return if new_attributes.empty?
41
40
 
42
- attributes = new_attributes.stringify_keys
41
+ attributes = new_attributes.stringify_keys
43
42
 
44
- _assign_nil_attributes(sanitize_for_mass_assignment(attributes))
45
- end
46
- end
43
+ _assign_nil_attributes(sanitize_for_mass_assignment(attributes))
44
+ end
47
45
 
48
- private
46
+ private
49
47
 
50
- unless private_method_defined?(:_assign_nil_attributes)
51
- # Assign any `nil` attribute
52
- #
53
- # @param attributes [Hash]
54
- #
55
- # @return [void]
56
- #
57
- def _assign_nil_attributes(attributes)
58
- attributes.each do |k, v|
59
- next unless v.nil?
48
+ # Assign any `nil` attribute
49
+ #
50
+ # @param attributes [Hash]
51
+ #
52
+ # @return [void]
53
+ #
54
+ def _assign_nil_attributes(attributes)
55
+ attributes.each do |k, v|
56
+ next unless v.nil?
60
57
 
61
- _assign_attribute(k, v)
62
- end
63
- end
58
+ _assign_attribute(k, v)
64
59
  end
65
- end
60
+ end
66
61
  end
67
62
  end
@@ -1,41 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  String.class_eval do
4
- unless method_defined?(:clean!)
5
- # Remove all non-UTF-8 chars from a string.
6
- #
7
- # @param replace_with [String, nil] What to replace invalid chars with.
8
- #
9
- # @return [String]
10
- #
11
- def clean!(replace_with = '')
12
- replace(encode('UTF-8', invalid: :replace, undef: :replace, replace: replace_with))
13
- end
4
+ # Remove all non-UTF-8 chars from a string.
5
+ #
6
+ # @param replace_with [String, nil] What to replace invalid chars with.
7
+ #
8
+ # @return [String]
9
+ #
10
+ def clean!(replace_with = '')
11
+ replace(encode('UTF-8', invalid: :replace, undef: :replace, replace: replace_with))
14
12
  end
15
13
 
16
- unless method_defined?(:clean)
17
- # @see {#clean!}
18
- def clean(replace_with = '')
19
- dup.clean!(replace_with)
20
- end
14
+ # @see {#clean!}
15
+ def clean(replace_with = '')
16
+ dup.clean!(replace_with)
21
17
  end
22
18
 
23
- unless method_defined?(:clean_binary!)
24
- # Remove all non-UTF-8 chars from a string and convert to binary.
25
- #
26
- # @param replace_with [String, nil] What to replace invalid chars with.
27
- #
28
- # @return [String]
29
- #
30
- def clean_binary!(replace_with = '')
31
- replace(encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: replace_with))
32
- end
19
+ # Remove all non-UTF-8 chars from a string and convert to binary.
20
+ #
21
+ # @param replace_with [String, nil] What to replace invalid chars with.
22
+ #
23
+ # @return [String]
24
+ #
25
+ def clean_binary!(replace_with = '')
26
+ replace(encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: replace_with))
33
27
  end
34
28
 
35
- unless method_defined?(:clean_binary)
36
- # @see {#clean_binary!}
37
- def clean_binary(replace_with = '')
38
- dup.clean_binary!(replace_with)
39
- end
29
+ # @see {#clean_binary!}
30
+ def clean_binary(replace_with = '')
31
+ dup.clean_binary!(replace_with)
40
32
  end
41
33
  end
@@ -1,13 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Enumerable.class_eval do
4
- if method_defined?(:compact_blank) && !method_defined?(:compact_blank_join)
5
- # Joins the elements together after calling `compact_blank`
6
- #
7
- # @return [String]
8
- #
9
- def compact_blank_join(using = '')
10
- compact_blank.join(using)
11
- end
4
+ # Joins the elements together after calling `compact_blank`
5
+ #
6
+ # @return [String]
7
+ #
8
+ def compact_blank_join(using = '')
9
+ compact_blank.join(using)
12
10
  end
13
11
  end
@@ -4,26 +4,22 @@ require 'forwardable'
4
4
  require 'set'
5
5
 
6
6
  Array.class_eval do
7
- unless method_defined?(:compact_map)
8
- # @return [Array]
9
- # Similar to `filter_map` but excludes `nil` instead of falsy
10
- def compact_map
11
- return to_enum(:compact_map) unless block_given?
7
+ # @return [Array]
8
+ # Similar to `filter_map` but excludes `nil` instead of falsy
9
+ def compact_map
10
+ return to_enum(:compact_map) unless block_given?
12
11
 
13
- r = []
14
- each do |*args|
15
- result = yield(*args)
16
- r.push(result) unless result.nil?
17
- end
18
- r
12
+ r = []
13
+ each do |*args|
14
+ result = yield(*args)
15
+ r.push(result) unless result.nil?
19
16
  end
17
+ r
20
18
  end
21
19
  end
22
20
 
23
21
  Set.class_eval do
24
- unless method_defined?(:compact_map)
25
- extend Forwardable
22
+ extend Forwardable
26
23
 
27
- def_delegators :to_a, :compact_map
28
- end
24
+ def_delegators :to_a, :compact_map
29
25
  end
@@ -3,10 +3,8 @@
3
3
  require 'date'
4
4
 
5
5
  DateTime.class_eval do
6
- unless method_defined?(:current_day)
7
- # :nodoc:
8
- def current_day
9
- beginning_of_day..end_of_day
10
- end
6
+ # :nodoc:
7
+ def current_day
8
+ beginning_of_day..end_of_day
11
9
  end
12
10
  end
@@ -3,19 +3,15 @@
3
3
  require 'date'
4
4
 
5
5
  DateTime.class_eval do
6
- unless method_defined?(:current_month)
7
- # :nodoc:
8
- def current_month
9
- beginning_of_month..end_of_month
10
- end
6
+ # :nodoc:
7
+ def current_month
8
+ beginning_of_month..end_of_month
11
9
  end
12
10
  end
13
11
 
14
12
  Date.class_eval do
15
- unless method_defined?(:current_month)
16
- # :nodoc:
17
- def current_month
18
- beginning_of_month..end_of_month
19
- end
13
+ # :nodoc:
14
+ def current_month
15
+ beginning_of_month..end_of_month
20
16
  end
21
17
  end
@@ -3,19 +3,15 @@
3
3
  require 'date'
4
4
 
5
5
  DateTime.class_eval do
6
- unless method_defined?(:current_week)
7
- # @return Range<DateTime>
8
- def current_week
9
- beginning_of_week..end_of_week
10
- end
6
+ # @return Range<DateTime>
7
+ def current_week
8
+ beginning_of_week..end_of_week
11
9
  end
12
10
  end
13
11
 
14
12
  Date.class_eval do
15
- unless method_defined?(:current_week)
16
- # @return Range<Date>
17
- def current_week
18
- beginning_of_week..end_of_week
19
- end
13
+ # @return Range<Date>
14
+ def current_week
15
+ beginning_of_week..end_of_week
20
16
  end
21
17
  end
@@ -3,19 +3,15 @@
3
3
  require 'date'
4
4
 
5
5
  DateTime.class_eval do
6
- unless method_defined?(:day_of_week)
7
- # @return [String] - Full day word
8
- def day_of_week
9
- strftime('%A')
10
- end
6
+ # @return [String] - Full day word
7
+ def day_of_week
8
+ strftime('%A')
11
9
  end
12
10
  end
13
11
 
14
12
  Date.class_eval do
15
- unless method_defined?(:day_of_week)
16
- # @return [String] - Full day word
17
- def day_of_week
18
- strftime('%A')
19
- end
13
+ # @return [String] - Full day word
14
+ def day_of_week
15
+ strftime('%A')
20
16
  end
21
17
  end
@@ -3,19 +3,15 @@
3
3
  require 'date'
4
4
 
5
5
  DateTime.class_eval do
6
- unless method_defined?(:display_military)
7
- # @return [String]
8
- def display_military(all = false)
9
- strftime(all ? '%m/%d/%Y %T' : '%-m/%-d/%y %T')
10
- end
6
+ # @return [String]
7
+ def display_military(all = false)
8
+ strftime(all ? '%m/%d/%Y %T' : '%-m/%-d/%y %T')
11
9
  end
12
10
  end
13
11
 
14
12
  Time.class_eval do
15
- unless method_defined?(:display_military)
16
- # @return [String]
17
- def display_military(all = false)
18
- to_datetime.display_military(all)
19
- end
13
+ # @return [String]
14
+ def display_military(all = false)
15
+ to_datetime.display_military(all)
20
16
  end
21
17
  end
@@ -3,28 +3,22 @@
3
3
  require 'date'
4
4
 
5
5
  DateTime.class_eval do
6
- unless method_defined?(:display_user)
7
- # @return [String] - mm/dd/yyyy HH:MM:SS AM/PM or m/d/yy HH:MM:SS AM/PM
8
- def display_user(all = false)
9
- strftime(all ? '%m/%d/%Y %r' : '%-m/%-d/%y %r')
10
- end
6
+ # @return [String] - mm/dd/yyyy HH:MM:SS AM/PM or m/d/yy HH:MM:SS AM/PM
7
+ def display_user(all = false)
8
+ strftime(all ? '%m/%d/%Y %r' : '%-m/%-d/%y %r')
11
9
  end
12
10
  end
13
11
 
14
12
  Time.class_eval do
15
- unless method_defined?(:display_user)
16
- # @return [String] - mm/dd/yyyy or m/d/yy
17
- def display_user(all = false)
18
- to_datetime.display_user(all)
19
- end
13
+ # @return [String] - mm/dd/yyyy or m/d/yy
14
+ def display_user(all = false)
15
+ to_datetime.display_user(all)
20
16
  end
21
17
  end
22
18
 
23
19
  Date.class_eval do
24
- unless method_defined?(:display_user)
25
- # @return [String] - mm/dd/yyyy or m/d/yy
26
- def display_user(all = false)
27
- strftime(all ? '%m/%d/%Y' : '%-m/%-d/%y')
28
- end
20
+ # @return [String] - mm/dd/yyyy or m/d/yy
21
+ def display_user(all = false)
22
+ strftime(all ? '%m/%d/%Y' : '%-m/%-d/%y')
29
23
  end
30
24
  end
@@ -4,21 +4,17 @@ require 'forwardable'
4
4
  require 'set'
5
5
 
6
6
  Array.class_eval do
7
- unless method_defined?(:find!)
8
- # :nodoc:
9
- def find!(&block)
10
- x = find(&block)
11
- raise(RubyRailsExtensions::Errors::NotFoundError, 'Not found') if x.nil?
7
+ # :nodoc:
8
+ def find!(&block)
9
+ x = find(&block)
10
+ raise(RubyRailsExtensions::Errors::NotFoundError, 'Not found') if x.nil?
12
11
 
13
- x
14
- end
12
+ x
15
13
  end
16
14
  end
17
15
 
18
16
  Set.class_eval do
19
- unless method_defined?(:find!)
20
- extend Forwardable
17
+ extend Forwardable
21
18
 
22
- def_delegators :to_a, :find!
23
- end
19
+ def_delegators :to_a, :find!
24
20
  end
@@ -1,16 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Array.class_eval do
4
- unless method_defined?(:find_dupes)
5
- # @param threshold [Integer] default 1
6
- #
7
- # @return [Array] excluding items that appear more than `threshold` times
8
- #
9
- def find_dupes(threshold = 1)
10
- results = select { |item| count(item) > threshold }
11
- results.uniq!
4
+ # @param threshold [Integer] default 1
5
+ #
6
+ # @return [Array] excluding items that appear more than `threshold` times
7
+ #
8
+ def find_dupes(threshold = 1)
9
+ results = select { |item| count(item) > threshold }
10
+ results.uniq!
12
11
 
13
- results
14
- end
12
+ results
15
13
  end
16
14
  end
@@ -1,11 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Array.class_eval do
4
- unless method_defined?(:first_dupe)
5
- # @param threshold [Integer] default 1
6
- # @return [*] first items that appears more than `threshold` times
7
- def first_dupe(threshold = 1)
8
- find { |item| count(item) > threshold }
9
- end
4
+ # @param threshold [Integer] default 1
5
+ # @return [*] first items that appears more than `threshold` times
6
+ def first_dupe(threshold = 1)
7
+ find { |item| count(item) > threshold }
10
8
  end
11
9
  end
@@ -3,10 +3,8 @@
3
3
  require 'date'
4
4
 
5
5
  DateTime.class_eval do
6
- unless method_defined?(:google_format)
7
- # @return [String] yyyy-mm-ddThh:mm:ss+hhmm
8
- def google_format
9
- strftime('%FT%T%z')
10
- end
6
+ # @return [String] yyyy-mm-ddThh:mm:ss+hhmm
7
+ def google_format
8
+ strftime('%FT%T%z')
11
9
  end
12
10
  end
@@ -1,27 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Hash.class_eval do
4
- unless method_defined?(:only)
5
- # The opposite of +Hash.except+.
6
- # ~/.rvm/gems/ruby-2.1.2/gems/activesupport-4.2.5/lib/active_support/core_ext/hash/except.rb
7
- # https://apidock.com/rails/Hash/except
8
- #
9
- # Selects only the supplied keys.
10
- #
11
- # http://api.rubyonrails.org/classes/Hash.html#method-i-slice
12
- #
13
- def only(*keys)
14
- slice(*keys)
15
- end
4
+ # The opposite of +Hash.except+.
5
+ # ~/.rvm/gems/ruby-2.1.2/gems/activesupport-4.2.5/lib/active_support/core_ext/hash/except.rb
6
+ # https://apidock.com/rails/Hash/except
7
+ #
8
+ # Selects only the supplied keys.
9
+ #
10
+ # http://api.rubyonrails.org/classes/Hash.html#method-i-slice
11
+ #
12
+ def only(*keys)
13
+ slice(*keys)
16
14
  end
17
15
 
18
- unless method_defined?(:only!)
19
- # See +only+
20
- #
21
- # http://apidock.com/rails/v4.1.8/Hash/extract%21
22
- #
23
- def only!(*keys)
24
- slice!(*keys)
25
- end
16
+ # See +only+
17
+ #
18
+ # http://apidock.com/rails/v4.1.8/Hash/extract%21
19
+ #
20
+ def only!(*keys)
21
+ slice!(*keys)
26
22
  end
27
23
  end
@@ -3,9 +3,7 @@
3
3
  require 'forwardable'
4
4
 
5
5
  Symbol.class_eval do
6
- unless method_defined?(:humanize)
7
- extend Forwardable
6
+ extend Forwardable
8
7
 
9
- def_delegators :to_s, :humanize
10
- end
8
+ def_delegators :to_s, :humanize
11
9
  end