Return ruby 中 require 语句的值
Return value of require statement in ruby
require 'lib'
的 return 值在 ruby 中表示什么,其中 'lib' 是任何想要包含的库?
例如当我 运行
>>> require 'nmatrix'
我得到 False
作为 return 值。这是什么意思?
这意味着,库已经加载。
require
Loads the given name, returning true if successful and false if the
feature is already loaded.
>> val = require 'set'
=> true
>> val_two = require 'set'
=> false
>> val
=> true
>> val_two
=> false
require returns false
如果给定的库已经加载。
>> require 'time'
=> true # time.rb was successfully loaded
>> require 'time'
=> false # time.rb was already found in-memory, it won't be loaded again
要求已加载的库在 Ruby 中无效。 return 标志在那里为您提供信息。 false
结果转换为:“你要求我加载这个库,但它已经在内存中,我不会再次加载它”。
另一方面,您有 load,它会在每次 调用时加载并执行文件名 的内容。
require 'lib'
的 return 值在 ruby 中表示什么,其中 'lib' 是任何想要包含的库?
例如当我 运行
>>> require 'nmatrix'
我得到 False
作为 return 值。这是什么意思?
这意味着,库已经加载。
require
Loads the given name, returning true if successful and false if the feature is already loaded.
>> val = require 'set'
=> true
>> val_two = require 'set'
=> false
>> val
=> true
>> val_two
=> false
require returns false
如果给定的库已经加载。
>> require 'time'
=> true # time.rb was successfully loaded
>> require 'time'
=> false # time.rb was already found in-memory, it won't be loaded again
要求已加载的库在 Ruby 中无效。 return 标志在那里为您提供信息。 false
结果转换为:“你要求我加载这个库,但它已经在内存中,我不会再次加载它”。
另一方面,您有 load,它会在每次 调用时加载并执行文件名 的内容。