[英]How does const_get work in mruby?
我將mruby 1.3.0 (2017-7-4)
與build_config.rb
:
MRuby::Build.new do |conf|
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
conf.gembox 'default'
conf.gem :git => 'https://github.com/mattn/mruby-uv'
conf.gem :git => 'https://github.com/mattn/mruby-http'
conf.gem :git => 'https://github.com/iij/mruby-socket'
conf.gem :git => 'https://github.com/luisbebop/mruby-polarssl.git'
conf.gem :git => 'https://github.com/iij/mruby-digest'
conf.gem :git => 'https://github.com/iij/mruby-pack'
conf.gem :git => 'https://github.com/matsumoto-r/mruby-simplehttp.git'
conf.gem :git => 'https://github.com/matsumotory/mruby-httprequest'
conf.gem :git => 'https://github.com/iij/mruby-aws-s3.git'
end
MRuby::Build.new('host-debug') do |conf|
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
conf.gembox 'default'
conf.cc.defines = %w(MRB_ENABLE_DEBUG_HOOK)
conf.gem :core => "mruby-bin-debugger"
end
MRuby::Build.new('test') do |conf|
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
conf.enable_bintest
conf.enable_test
conf.gembox 'default'
end
我在ruby中發現const_get
方法與在ruby中有所不同。 在ruby(2.4.0p0)中, Class.const_get('Fixnum')
返回常量Fixnum
,而在mruby中, Class.const_get('Fixnum')
導致uninitialized constant Class::Fixnum (NameError)
。
然后,我嘗試了另一個示例: class Hoge; end; class Hoge::Fuga; end
class Hoge; end; class Hoge::Fuga; end
class Hoge; end; class Hoge::Fuga; end
。 在紅寶石中, Class.const_get('Hoge::Fuga')
和Hoge.const_get('Fuga')
給出常數Hoge::Fuga
。 在mruby中,只有Hoge.const_get('Fuga')
返回Hoge::Fuga
。
mruby的Module#const_get
像第二個參數的工作原理(名為inherit
搜索超) false
的CRuby。 如果使用Object.const_get(:Integer)
則其行為應與mruby和CRuby中的預期相同。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.