Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

Understanding ".with" in Ruby

Sorry this is probably a question that has been asked many times but as it regards what is a very common word in English it is pretty much impossible to google or search for it.

I have seen a few examples of Ruby code which looks like this:

EnquiryNotification.with(post: @post)

I'm trying to understand what the ".with" part does. Can anyone shed some light on this please?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

with is a class method defined on the EnquiryNotification class (or one of its ancestors). The method is neither a keyword in the Ruby language nor is it a common method on classes shipped with Ruby itself or its standard library. As such, to find what this method does, you would likely have to consult the documentation of your chosen framework or application.

An example of a with method defined in a framework is Sequel::Dataset#with to add a CTE to the current query. The method is also available as a class method in Sequel model classes.

It could also be part of ActionMailer as mentioned by Stefan in a comment above.

In any case though, make sure to consult the documentation of your chosen framework or library for details.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...