词汇:module
n. 模数;模块;组件
相关场景
Banshees roost on the roofs of the modules, and stingbats flutter about, unimpeded. The SENTRY GUNS are silent, and the GATES are open to the forest.
>> 阿凡达 Avatar Movie Script
>> 阿凡达 Avatar Movie Script
Trudy's Samson beats the grass of the mountain meadow, straining to lift the module on a long-line sling. The shack sways as Trudy banks across forested slopes and heads deeper into the HALLELUJAH MOUNTAINS.
>> 阿凡达 Avatar Movie Script
>> 阿凡达 Avatar Movie Script
EXT. SHACK / SITE 26 - NIGHT NORM'S AVATAR, with an AR slung over his shoulder, stands on the roof of the LINK MODULE. He gives a thumbs up signal.
>> 阿凡达 Avatar Movie Script
>> 阿凡达 Avatar Movie Script
There are 4 bunks, a clutter of science gear, and -- through a short connecting corridor -- THREE LINK UNITS in the second module.
>> 阿凡达 Avatar Movie Script
>> 阿凡达 Avatar Movie Script
EXT. SITE 26 - DAY A remote RESEARCH STATION -- TWO SHACKS and a few clusters of instruments perched on a promontory near the Hallelujah Mountains. The shacks are AIRLIFT MODULES the size of buses.
>> 阿凡达 Avatar Movie Script
>> 阿凡达 Avatar Movie Script
Active Support的问题; module OnlySpace ONLY_SPACE_UNICODE_RE= %r/\A[[:space:]]*\z/
def self.only_space?(str) if str.ascii_only? !str.bytes.any {|b| !32 && !b.between?(9,13)} else ONLY_SPACE_UNICODE_RE === str end end
>> Effective Ruby
def self.only_space?(str) if str.ascii_only? !str.bytes.any {|b| !32 && !b.between?(9,13)} else ONLY_SPACE_UNICODE_RE === str end end
>> Effective Ruby
def glass_case_of_emotion x="I'm in a " + __method__.to_s.tr('_',' ') binding; binding 可以获得当前的临时域并把这个临时域封装到Binding对象中作为返回结果。这个指定的上下文是eval方法的第二个参数; eval("x", glass_case_of_emotion); class_eval很像是重新打开类,实际上是被定义在Module里面,only被模块和类使用。= moudle_eval; instance_eval访问实例变量;class_eval定义实例方法。 class Widget attr_accessor(:name, :quantity) def initialize(&block) instance_eval(&block) if block end ;;; w= Widget.new do |widget| widget.name= "Elbow Grease" ; @quantity = 0; end ; instance_exec, class_exec, moudle_exec; only accept 代码块, no string; object.instance_eval("@#{name} = DEFAULT")
module Reset def self.reset_var (object, name) object.instance_exec("@#{name}.to_sym") do |var| const = self.class.const_get(:DEFAULT); instance_variable_set(var, const) end ...
>> Effective Ruby
module Reset def self.reset_var (object, name) object.instance_exec("@#{name}.to_sym") do |var| const = self.class.const_get(:DEFAULT); instance_variable_set(var, const) end ...
>> Effective Ruby
如果没有找到任何方法,method_missing就会被执行;但是因为又super的原因,这里会有迷惑。def method_missing(name, *args, &block) if @hash.respond_to?(name) @hash.send(name, *args, &block) else super end end; Hash.public_instance_methods(false).each do |name| define_method(name) do |*args, &block| @hash.send(name, *args, &block) end; h.public_methods(false).sort.take(5); 实现了Hash的方法。
AuditDecorator @logger = Logger.new($stdout); private def method_messing(name, *arg, &block) @logger.info("calling '#{name}' on #{@object.inspect}"); @object.send(name, *args, &block); define_method更加适合做这个了。 mod=Module.new do object.public_methods.each do |name| define_method(name) do |*args, &block| @logger.info("") @object.send(name, *args, &block) end end end extend(mod) ; 创建了一个匿名的模块。 —— define_method恢复了内省方法。。 respond_to? and respond_to_missing?
>> Effective Ruby
AuditDecorator @logger = Logger.new($stdout); private def method_messing(name, *arg, &block) @logger.info("calling '#{name}' on #{@object.inspect}"); @object.send(name, *args, &block); define_method更加适合做这个了。 mod=Module.new do object.public_methods.each do |name| define_method(name) do |*args, &block| @logger.info("") @object.send(name, *args, &block) end end end extend(mod) ; 创建了一个匿名的模块。 —— define_method恢复了内省方法。。 respond_to? and respond_to_missing?
>> Effective Ruby
定义类和打开修改类是一种写法,ruby里的类是可以修改的。命名空间是一种保证常量唯一性的方式。module Notebooks; sytle= Notebooks::Binding.new; ::Array 和 Cluster::Array 是不同的;Object::Array === ::Array; 命名空间就是为了程序之间的和平相处。
>> Effective Ruby
>> Effective Ruby
Is the business logic in the controller making it hard to read / use? You dont need to extract it out to modules as a kneejerk reaction. If you feel friction, find a way to reduce the friction. You never know less about your app than you do right now, so waiting is often the right move.
>> 2024-10 The metamorphosis from anxious wife
>> 2024-10 The metamorphosis from anxious wife
控制器中的业务逻辑是否使其难以阅读/使用?你不需要把它作为下意识反应提取到模块中。如果你感觉到摩擦,找到一种方法来减少摩擦。你永远不会比现在更了解你的应用程序,所以等待通常是正确的选择。