`
fireflyman
  • 浏览: 113714 次
  • 性别: 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

    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

    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 ...

    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 ...

    .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 ...

    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 ...

    Packtpub.Python.2.6.Text.Processing.Beginners.Guide.Dec.2010

    Extract, decrypt, parse, restructure – these are just some of the text tasks that can occupy much of a programmer’s life. If this is your life, this book will make it better – a practical guide on...

    端口查看工具

    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

    Production Testing of RF and System-on-a-Chip Devices for Wireless Communications((Artech.House.Publishers.Apr.2004)

    device functions are contained within one chip or module. Furthermore, the integration levels are such that RF chips contain lower-frequency analog functionality, as well as digital functionality ...

    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;...

    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. ...

    iphone5s拆解图解

    [size=1em]We quickly extract the home button and Touch ID, Apple's new fingerprint scanner. Time to dust for prints! o [size=1em]A CMOS chip, the Touch ID is essentially a bunch of very small ...

    CE中文版-启点CE过NP中文.exe

    You can now drop files into the auto assembler auto assembler commands allocnx (allocate no execute) and allocxo (allocate execute only) The memoryview windows's hexadecimalview now shows the ...

    Visual C++ 编程资源大全(英文源码 DLL)

    04.zip Determine DLL version number 检测DLL的版本号(7KB)&lt;END&gt;&lt;br&gt;5,05.zip Getting the complete information about DLL/Exe module 得到DLL/EXE模块的编译信息(5KB)&lt;END&gt;&lt;br&gt;6,06.zip Using one...

    acpi控制笔记本风扇转速

    Restructured the AML ParseLoop function, breaking it into several subfunctions in order to reduce CPU stack use and improve maintainability. (Mikhail Kouzmich) AcpiGetHandle: Fix for parameter ...

Global site tag (gtag.js) - Google Analytics