In Ruby, is require('my_thing')
equivalent to require 'my_thing'
? It's just the ruby convention that you don't need to wrap a function's arguments in paranetheses right?
You are right, you don't need them, however, I think you need to know one important thing before deciding to ditch them all-together in your method calls (regarding your question on conventions):
According to the Ruby Style Guide :
Omit parentheses around parameters for methods that are part of an internal DSL (eg Rake, Rails, RSpec), methods that have "keyword" status in Ruby (eg attr_reader, puts) and attribute access methods. Use parentheses around the arguments of all other method invocations.
Since require
has a "keyword" status in Ruby, it's okay to not use parentheses. If, however, you made your own my_require
method, then it would be a better idea to use them.
Allowing omission of parentheses around the argument is a language feature , not a convention.
It is a convention to omit parentheses for methods defined on the Kernel
module that start with lower case. require
is one of them.
You do not need parenthesis for this. require('my_thing')
is equivalent to require 'my_thing'
. You are correct that this is just ruby convention.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.