⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 00 - introduction

📁 O Reilly Ruby Cookbook source code
💻
字号:
require 'set' # Deals with a collection of unordered values with no duplicates# Include this module to make your class taggable. The names of the# instance variable and the setup method are prefixed with "taggable_"# to reduce the risk of namespace collision. You must call# taggable_setup before you can use any of this module's methods.module Taggable  attr_accessor :tags  def taggable_setup    @tags = Set.new  end  def add_tag(tag)    @tags << tag  end  def remove_tag(tag)    @tags.delete(tag)  endendmodule Taggable2  def initialize(a,b,c)  endend#---class TaggableString < String  include Taggable  def initialize(*args)    super    taggable_setup  endends = TaggableString.new('It was the best of times, it was the worst of times.')s.add_tag 'dickens's.add_tag 'quotation's.tags                               # => #<Set: {"dickens", "quotation"}>#---module Complaint   def gripe    voice('In all my years I have never encountered such behavior...')  end  def faint_praise    voice('I am pleased to notice some improvement, however slight...')  end  def voice(complaint_text)    raise NotImplementedError,    "#{self.class} included the Complaint module but didn't define voice!"  endendclass MyComplaint  include ComplaintendMyComplaint.new.gripe# NotImplementedError: MyComplaint included the Complaint module# but didn't define voice!#---module Ayto  def potato    'Pohtayto'  endendmodule Ahto  def potato    'Pohtahto'  endend#---class Potato  include Ayto  include Ahtoend#---Potato.new.potato                                    # => "Pohtahto"#---

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -