请求了解ruby代码

请求了解ruby代码,ruby,Ruby,我的团队一直在阅读现有的ruby代码来建立我们的理解。我们通常会发现一些我们不太了解的事情,即使是通过研究。请就以下问题发表意见 问题1 对于下面的代码,为什么类有一点解释: class@sawa我本来想评论一些类似的东西,但后来意识到这些问题似乎彼此紧密相连,可能不太容易分开。Idk虽然…@Ajedi32我理解你的意思,但总的来说,它太长了。它需要更加简洁,或者分开。相关: module GravatarImageTag class << self attr_acce

我的团队一直在阅读现有的ruby代码来建立我们的理解。我们通常会发现一些我们不太了解的事情,即使是通过研究。请就以下问题发表意见

问题1
对于下面的代码,为什么
有一点解释:


class@sawa我本来想评论一些类似的东西,但后来意识到这些问题似乎彼此紧密相连,可能不太容易分开。Idk虽然…@Ajedi32我理解你的意思,但总的来说,它太长了。它需要更加简洁,或者分开。相关:
module GravatarImageTag

  class << self
    attr_accessor :configuration
  end
module GravatarImageTag

  class << self
    attr_accessor :configuration
  end

  def self.configuration
    @configuration ||= Configuration.new
  end

  def self.configure
    yield(configuration)
  end
module GravatarImageTag

  class << self
    attr_accessor :configuration
  end

  def self.configuration
    @configuration ||= Configuration.new
  end

  def self.configure
    yield(configuration)
  end

  class Configuration
     attr_accessor :default_image, :filetype, :include_size_attributes,
       :rating, :size, :secure

     def initialize
        @include_size_attributes = true
     end
  end

  def self.included(base)
    GravatarImageTag.configure { |c| nil }
    base.extend ClassMethods
    base.send :include, InstanceMethods
  end   
class Foo
  class << self
    def a
      print "I could also have been defined as def Foo.a."
    end
  end
end
str = "abc"
other_str = "def"

class << str
  def frob
    return self + "d"
  end
end

print str.frob # => "abcd"
print other_str.frob # => raises an exception, 'frob' is not defined on other_str