`
sqlxx
  • 浏览: 16651 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

About class << self in ruby

 
阅读更多

在ruby中经常可以见到这样的写法:

class A
  class << self
     def hello
        puts "hello"
     end
   end
end

这样的写法和

class A
  def self.hello
     puts "hello"
   end
end

可以说是完全一样的。第一种写法的一个好处是,如果需要在一个class或者module里面定义多个类级别的方法, 这种写法可以少写很多个"self." :)

还有一个好处是,可以使用attr_reader/attr_accessor 之类的meta programming的method.



分享到:
评论

相关推荐

    Design Patterns in Ruby

    information about applying the Ruby platform to create dynamic technology solutions. The series is based on the premise that the need for expert reference books, written by experienced practitioners, ...

    Sams - Teach Yourself Ruby in 21 Days.pdf

    and you’ve seen bookstore shelves overflowing with programming&lt;br&gt;titles.&lt;br&gt;What is unusual is that Ruby is a very advanced programming language, yet this book&lt;br&gt;claims to teach it to you while ...

    Ruby-Way.rar_About Language

    Ruby Way by Hal fulton its about Ruby language programming

    ruby cookbook

    like how to blink the lights on your keyboard.&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;The Ruby Cookbook is the most useful book yet&lt;br&gt;written about Ruby. When you need to solve a problem, don't reinvent&lt;br&gt;the wheel: ...

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

    A class for gathering file information recursively through directories(63KB)&lt;END&gt;&lt;br&gt;7,self_extractor.zip&lt;br&gt;A class that allows you to create self extracting executables for use in distribution or ...

    ruby and watir 安装指南

    Here is some information about the versions of softwares I'm using OS: Windows XP Browser: Firefox 3.6.8 Ruby: 1.8.7 Gems: 1.3.7 Watir: 1.6.5 FireWatir: 1.6.5 I would really appreciate all the help....

    ruby-language-quickref.zip_About Language

    A quick tutorial about Ruby on Rails

    All About: File I/O in C++

    All About: File I/O in C++&lt;br&gt;By Ilia Yordanov, loobian@cpp-home.com&lt;br&gt;&lt;br&gt;This tutorial may not be republished without a written permission from the author!&lt;br&gt;&lt;br&gt;Introduction&lt;br&gt;&lt;br&gt;This tutorial ...

    About Window Class Style.pdf

    The class styles define additional elements of the window class. Two or more styles can be combined by using the bitwise OR (|) operator. To assign a style to a window class, assign the style to the ...

    Sam's Teach Yourself Data Structures And Algorithms In 24 Hours

    What’s Different About This Book&lt;br/&gt;There are dozens of books on data structures and algorithms. What’s different about this&lt;br/&gt;one? Three things:&lt;br/&gt;● Our primary goal in writing this book is ...

    Programming Ruby 1.9 & 2.0 The Pragmatic Programmers’ Guide 4th Edition

    including a description of all the standard library modules, a complete reference to all built-in classes and modules (including all the new and changed methods introduced by Ruby 1.9, 1.9.2, 1.9.3, ...

    Ford's ApproachTo Developing Self-Driving Vehicle

    5 Best in class partners: working with Argo AI 6 How we earn trust-Applying safety processes 7 How we earn trust-Designing for reliability 8 How we earn trust-Delivering a valuable customer experience...

    Pro ActiveRecord Databases

    &lt;br&gt;or maybe as a chapter or two, within a larger scoped book generally about the Ruby on&lt;br&gt;Rails (RoR) framework. And almost all of those books actually do a great job of introducing&lt;br&gt;you to the ...

    About Time AND Timer sample in STEP7_20070903a.zip西门子PLC编程实例程序源码

    About Time AND Timer sample in STEP7_20070903a.zip西门子PLC编程实例程序源码About Time AND Timer sample in STEP7_20070903a.zip西门子PLC编程实例程序源码About Time AND Timer sample in STEP7_20070903a.zip...

    Visualization Handbook PDF part 2 of 2

    The field of visualization is focused on creating&lt;br&gt;images that convey salient information about&lt;br&gt;underlying data and processes. In the past&lt;br&gt;three decades, the field has seen unprecedented&lt;br&gt;...

    H5 jQuery CSS3带时钟幻灯片自动轮播特效.zip

     &lt;li&gt; &lt;a &gt; &lt;i class="fa fa-edit"&gt;&lt;/i&gt; &lt;strong&gt;About us&lt;/strong&gt; &lt;small&gt;sweet home&lt;/small&gt; &lt;/a&gt; &lt;/li&gt;  &lt;li&gt; &lt;a &gt; &lt;i class="fa fa-gift"&gt;&lt;/i&gt; &lt;strong&gt;Features&lt;/strong&gt; &lt;small&gt;sweet home&lt;/small&gt; &lt;/a&gt; ...

    如家宠物网站

    xml=&lt;data&gt;&lt;config&gt;&lt;isShowTitle&gt;0&lt;/isShowTitle&gt;&lt;autoPlayTime&gt;5&lt;/autoPlayTime&gt;&lt;/config&gt;&lt;channel&gt;&lt;item&gt;&lt;link&gt;&lt;/link&gt;&lt;image&gt;images/0411412705084558.jpg&lt;/image&gt;&lt;title&gt;&lt;/title&gt;&lt;/item&gt;&lt;item&gt;&lt;link&gt;&lt;/link&gt;...

    Beginning Ruby on Rails

    On the other hand, Beginning Ruby on Rails is all about programming, so if you have programming expe- rience, that will be helpful. If you want to know how to create Ruby on Rails online applications,...

    All New Electronics Self Teaching Guide (Self-Teaching Guides) by Harry Kybett

    Three things Boysen's book were unclear about are: ground line in circuits, which doesn't even show up in the index and is assumed to be something the reader knows beforehand; combining AC and DC in ...

Global site tag (gtag.js) - Google Analytics