I am a beginner in Ruby and had this question nagging me for a long time.
In an RSpec file , if we write Book.should <do something> , what is the should keyword? Is it a member of the Book object? How did it come to be the member of the Book object? Or is it some construct of Ruby? Is it a function? Where can i find the definition of this if it is a function or member?
Upon loading, RSpec includes a module into the
Kernelmodule which is included into all objects known to Ruby. Thus, it can make the should method available to all objects. As such,shouldis not a keyword (likeif,class, orend) but an ordinary method.Note that that mixin is only available in RSpec contexts as it is “patched in” during loading or RSpec.