While writing some specs, I came in need or the following assertion:
my_json.should == [
“identifier" => :ANY_STRING,
"name" => “Super Name",
“pos" => 3
"identifier" => :ANY_STRING
"name" => "Super Name",
“pos" => 2,
Yes, I want to match regardless of the string contained in the identifier. Obviously I could removed this key from the hashes and do the match.
But wouldn’t it be sweet if that symbol would match any string?
Since we are using ruby it is quite easy to overwrite the built in methods:
return true if string.is_a?(Symbol) && string == :ANY_STRING
I would not consider this kind of monkey patch a good practice, however...One of the things I love about ruby is the fact that it let’s you do crazy stuff.
In addition, one of the things I don’t love about ruby is the fact that it let’s you make crazy stuff.
Like the Spider Man knows well, with great power comes great responsibility.