在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.
分享到:
相关推荐
and the description "Ruby.Pocket.Reference.Jul.2007 learning ruby 的 can reference" indicate that this is a concise guide designed to provide quick access to essential information about the Ruby ...
like how to blink the lights on your keyboard.<br><br><br><br><br>The Ruby Cookbook is the most useful book yet<br>written about Ruby. When you need to solve a problem, don't reinvent<br>the wheel: ...
《Ruby Way》是由Hal Fulton编写的关于Ruby编程语言的一本著作。这本书深入浅出地探讨了Ruby语言的各种特性,旨在帮助读者理解并掌握这门强大的动态脚本语言。Ruby以其简洁、优雅的语法和强大的元编程能力而备受赞誉...
A class for gathering file information recursively through directories(63KB)<END><br>7,self_extractor.zip<br>A class that allows you to create self extracting executables for use in distribution or ...
This directory contains the Dalvik virtual machine and core class library, as well as related tools, libraries, and tests. A note about the licenses and header comments ------------------------------...
在"ruby-language-quickref.zip_About Language"这个压缩包中,我们重点关注的是Ruby语言本身的基础知识和特性。"ruby language quickref.pdf"很可能是一个Ruby语言速查指南,涵盖了语言的关键概念和语法。 首先,...
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...
class PagesController < HighVoltage::Pages # 添加你自己的逻辑,如权限控制、缓存策略等 end ``` ### 高级用法 1. **分页**:尽管High Voltage主要用于单个静态页面,但通过自定义控制器,你可以实现多页内容...
<br>or maybe as a chapter or two, within a larger scoped book generally about the Ruby on<br>Rails (RoR) framework. And almost all of those books actually do a great job of introducing<br>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...
The field of visualization is focused on creating<br>images that convey salient information about<br>underlying data and processes. In the past<br>three decades, the field has seen unprecedented<br>...
<% for row in @search.facet(:search_class).rows %> <li> <% if params[:class].blank? %> <%= row.count %> <%= link_to(row.value, :class => row.value) %> <% else %> <strong><%= row.value %></strong...
class Matz < Person def initialize super('Yukihiro Matsumoto') end end puts Matz.new.greet # 输出 "Hello, my name is Yukihiro Matsumoto." ``` ### 5. 控制结构 Ruby提供了常见的控制结构,如条件语句...
<li> <a > <i class="fa fa-edit"></i> <strong>About us</strong> <small>sweet home</small> </a> </li> <li> <a > <i class="fa fa-gift"></i> <strong>Features</strong> <small>sweet home</small> </a> ...
xml=<data><config><isShowTitle>0</isShowTitle><autoPlayTime>5</autoPlayTime></config><channel><item><link></link><image>images/0411412705084558.jpg</image><title></title></item><item><link></link>...
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 ...
Wave<br>Transmission Line 379<br>10.9 Class G and H Amplifiers 381<br>10.10 Class S Amplifiers 383<br><br>xiv Radio Frequency Integrated Circuit Design<br>10.11 Summary of Amplifier Classes for RF ...