`
fireflyman
  • 浏览: 118340 次
  • 性别: Icon_minigender_1
  • 来自: 火星
社区版块
存档分类
最新评论

Extract into Module

    博客分类:
  • ROR
阅读更多

有些代碼我們可以把它們提取出來,這可以方便我們重用這部分代碼.如下面這段:
原文參考:http://rails-bestpractices.com/posts/17-extract-into-module

重構前:
class User < ActiveRecord::Base
  validates_presence_of :cellphone
  before_save :parse_cellphone

  def parse_cellphone
    # do something
  end
end


重構后:
module HasCellphone
  def self.included(base)
    base.validates_presence_of :cellphone
    base.before_save :parse_cellphone
  end

  def parse_cellphone
    # do something
  end
end

class User < ActiveRecord::Base
  include HasCellphone
end
分享到:
评论

相关推荐

    ps4_module_loader:PS4模块加载程序IDA 7.0-7.5

    PS4 Module Loader SocraticBliss (R) Major Thanks to.... zecoxaoInstallationIDA 7.0 - 7.2 Extract the IDA70-72.zip directory into your IDA directory (overwite the files when prompted)IDA 7.5 (Requires Pyt

    基于单片机的指纹识别门禁系统设计说明.pdf

    These algorithms extract unique features from a captured fingerprint image, converting it into a template that can be compared with stored templates for authentication. The FM-180 module's hardware ...

    sveltejs-brunch:在 Brunch 项目中编译 Svelte 组件

    sveltejs-早午餐 在项目中编译组件。 将 CSS 提取到一个单独的... // To extract the CSS into files, simply include to extractCSS option in your Brunch config like so... extractCSS : true , // To combine

    使用IntelliJ Idea 打包成可执行的JAR.docx

    通过展开Dll,选中所有jar包,右键选择`Extract Into Output Root`,目的是将这些依赖项与Client模块合并,使它们能在运行时被正确加载。 6. 配置完成后,点击`OK`,然后通过`Build`菜单下的`Build Artifacts`来...

    Scala: Guide for Data Science Professionals

    Once you have become familiar with all the tasks involved in data science, you will explore data analytics with Scala in the second module. You'll see how Scala can be used to make sense of data ...

    IntelliJIDEA_ReferenceCard_Mac

    - Steps into the next line of code, intelligently choosing whether to enter a method based on where the next breakpoint is set. 4. **Step Out**: `F8` - Steps out of the current method. 5. **Run to...

    sass-resources-loader:用于Webpack的SASS资源(例如变量,mixins等)的加载器。 也适用于less,post-css等

    sass-resources-loader 该加载程序会将您的SASS资源加载到每个required SASS模块中。 因此,您可以在所有SASS样式中使用共享变量,mixin和函数,而无需在每个文件中手动加载它们。 适用于CSS模块!...

    Gradle.Essentials.1783982365

    Extract common build logic into plugins Write builds for languages like Java, Groovy, and Scala In Detail Gradle is an advanced and modern build automation tool. It inherits the best elements of the ...

    Refactoring(2008-01-12)-1.wmv

    - 将重复的代码提取到基类或共用模块(Extract Base Class or Module):减少代码重复,提高代码复用。 重构是一个持续的过程,需要在开发过程中不断进行,以保持代码的健康状态。通过学习和应用这些重构技术,...

    .net的矛与盾 软件保护与软件破解程序源代码(收集reflector最全插件,大部分有源代码)

    18.BizTalkDisassembler: Allows you to list all BizTalk artifacts contained in an assembly and extract them. 19. DependencyStructureMatrix: Allows you to create and browser dependency structure ...

    Cours-VB-NET-2010-Developpez-com

    Based on the given information from "Cours-VB-NET-2010-Developpez-com," we can extract several key points and concepts related to Visual Basic .NET (VB.NET) 2010. The course is designed for beginners ...

    au3反编译源码

    Drag the compiled *.exe or *.a3x into the AutoIT Script Decompiler textbox. To copy text or to enlarge the log window double click on it. Supported Obfuscators: 'Jos van der Zande AutoIt3 Source ...

    端口查看工具

    o Added Module Filename column (works only on XP/SP2) * Version 1.36: o Fixed bug: The main window lost the focus when the user switched to another application and then returned back to CurrPorts....

    drupal 6.12

    http://drupal.org/project/translations and download the package. Extract the contents to the same directory where you extracted Drupal into. 2. CREATE THE CONFIGURATION FILE AND GRANT WRITE ...

    FVCNN: Fusion View Convolutional Neural Networks for Non-rigid 3D Shape Classification and Retrieval

    Most 3D shape classification and retrieval algorithms were based on rigid 3D shapes, deploying these algorithms directly ... We first propose a projection module to transform the nonrigid 3D shape into a

    VB编程资源大全(英文源码 其它)

    This is used to make 3D text.&lt;END&gt;&lt;br&gt;27 , basMath.zip This module contains functions for various math equations. &lt;END&gt;&lt;br&gt;28 , calc.zip This is a basic calculator written in Visual Basic.&lt;END&gt;...

    i.MX Linux® Reference Manual

    Based on the given information from the "i.MX Linux® Reference Manual," we can extract several key topics and concepts that are essential for understanding the Linux environment tailored for ...

    vmware unlocker 2.0.6最新版(vm虚拟机破解安装Mac OS)

    (10.5 and 10.6) you must use a replacement EFI firwmare module from the firmware folder. If you are using a 32-bit installation of OS X: 1. Copy efi32-srvr.rom to guest folder. 2. Edit the vmx file ...

    eric5-5.3.1

    to do that, simply extract the downloaded archives into the same place as the eric5 archive and follow the installation instructions above. The second possibility is to install them separately. ...

Global site tag (gtag.js) - Google Analytics