Runtime assertions for Ruby literal.fun
ruby
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: Better predicates support for SCREAMING_ENUM (#317)

authored by

Alexey Zapparov and committed by
GitHub
24a269ab 6739fe20

+9 -3
+1 -1
lib/literal/enum.rb
··· 88 88 if self === object 89 89 # object.instance_variable_set(:@name, name) 90 90 @names[object] = name 91 - define_method("#{name.to_s.gsub(/([^A-Z])([A-Z]+)/, '\1_\2').downcase}?") { self == object } 91 + define_method("#{name.to_s.gsub(/([^A-Z])([A-Z]+)/, '\1_\2').gsub(/_{2,}/, '_').downcase}?") { self == object } 92 92 object.freeze 93 93 end 94 94 end
+8 -2
test/enum.test.rb
··· 14 14 Red = new(1, hex: "#FF0000") 15 15 Green = new(2, hex: "#00FF00") 16 16 Blue = new(3, hex: "#0000FF") 17 + SPRING_GREEN = new(4, hex: "#00FF7F") 17 18 18 19 __after_defined__ if RUBY_ENGINE == "truffleruby" 19 20 end ··· 107 108 assert_equal Color.to_set, Set[ 108 109 Color::Red, 109 110 Color::Green, 110 - Color::Blue 111 + Color::Blue, 112 + Color::SPRING_GREEN 111 113 ] 112 114 end 113 115 ··· 116 118 Color::Red => 1, 117 119 Color::Green => 2, 118 120 Color::Blue => 3, 121 + Color::SPRING_GREEN => 4, 119 122 } 120 123 end 121 124 ··· 130 133 test "#succ" do 131 134 assert_equal Color::Red.succ, Color::Green 132 135 assert_equal Color::Green.succ, Color::Blue 133 - assert_equal Color::Blue.succ, nil 136 + assert_equal Color::Blue.succ, Color::SPRING_GREEN 137 + assert_equal Color::SPRING_GREEN.succ, nil 134 138 end 135 139 136 140 test "#pred" do ··· 182 186 assert_equal Color::Red.red?, true 183 187 assert_equal Color::Red.green?, false 184 188 assert_equal Color::Red.blue?, false 189 + assert_equal Color::Red.spring_green?, false 190 + assert_equal Color::SPRING_GREEN.spring_green?, true 185 191 end 186 192 187 193 test "members are frozen" do