it-ebooks - Ruby中的元编程
Here you can read online it-ebooks - Ruby中的元编程 full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2016, publisher: iBooker it-ebooks, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:
Romance novel
Science fiction
Adventure
Detective
Science
History
Home and family
Prose
Art
Politics
Computer
Non-fiction
Religion
Business
Children
Humor
Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.
Ruby中的元编程: summary, description and annotation
We offer to read an annotation, description, summary or preface (depends on what the author of the book "Ruby中的元编程" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.
Ruby中的元编程 — read online for free the complete book (whole text) full work
Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Ruby中的元编程" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.
Font size:
Interval:
Bookmark:
,
Free Mind
lexyacc
CLispC++
evalLispquinequine
LispPythonRubyevalRuby
LispJohn M. VlissidesPattern Languages of Program Design
Lispreflective programmingmetaprogrammingSmalltalk2070LispCommanObjVlisp[Bobrow+86Cointe87]Metaobject Protocal[Kiczales+91]IBM SOM
Meta
RubyRuby
Rubyattr_accessor
LispSLispLispevaluateVariable CaptureLispLisp
RubyParseTreeParseTreeRubySHeckleRuby'true''false'
Rubyalias
- Ruby's Metaprogramming toolbox:http://weare.buildingsky.net/2009/08/25/rubys-metaprogramming-toolbox
- Metaprogramming in Ruby:http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/
- Practical Metaprogramming with Ruby: Storing Preferences:http://www.kalzumeus.com/2009/11/17/practical-metaprogramming-with-ruby-storing-preferences/
- The Ruby Object Model and Metaprogramming:http://pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogramming
- Metaprogramming Ruby: class_eval and instance_eval:http://jimmycuadra.com/posts/metaprogramming-ruby-class-eval-and-instance-eval
- Metaprogramming in Ruby:http://rubyrogues.com/metaprogramming-in-ruby/
Instance Variables
Instance Methods
Class
Class
Class
Object
Object
Object
BasicObject
Ruby- Constant
# .methods == . class .instance_methods #=> true # N = Class .new N .ancestors #=> [N, Object, Kernel, BasicObject] N . class #=> Class N .superclass #=> Object N .superclass.superclass #=> BasicObject N .superclass.superclass.superclass #=> nil
RubyString
Array
Ruby 2.0refine
class String def writesize self .size end end puts "Tell me my size!" .writesize
!
BUGcaptalize()
String
captalize()
OverloadingRectangule
Rectangule
Rubyinitialize
initialize
initialize
# The Rectangle constructor accepts arguments in either # of the following forms: # Rectangle.new([x_top, y_left], length, width) # Rectangle.new([x_top, y_left], [x_bottom, y_right]) class Rectangle def initialize(*args) if args.size < || args.size > puts 'Sorry. This method takes either 2 or 3 arguments.' else puts 'Correct number of arguments.' end end end Rectangle .new([, ], , ) Rectangle .new([, ], [, ])
Rectangule
initialize
initialize
Anonymous ClassSingleton ClassEigenclassGhost ClassMetaclassuniclass
eigenclasssinglton classesmetaclassesthe class of a classRubyMatzeigenclasseigenones owneigenclassan objects own classeigenclassSinglton Methods))
David Hilbert 1904 EigenEigenclass Ruby
RubyRubyHidden
# 1 class Rubyist def self .who "Geek" end end # 2 class Rubyist class < < self def who "Geek" end end end # 3 class Rubyist end def Rubyist .who "Geek" end #4 class Rubyist end Rubyist .instance_eval do def who "Geek" end end puts Rubyist .who # => Geek # 5 class < < Rubyist def who "Geek" end end
5Rubylist.who
"Geek"
#5class
<<
<<
Complete Ruby Class Diagram Ruby 1.8.6Artem SRubyRuby 2.0.0
Ruby
- method lookup
- Ruby
self
Rubyreceiverancestors chainan_object.display()
an_object
RubyObject
BasicObject
Ruby
Rubyreceiverone step to the right, then uprecivermethod_missing
NoMethodError
Ruby
class A def foo end end class B < A def bar # bar method in B end end class C < B def bar # bar method in C # overwriting superclass' method end end obj = C .newobj.bar #=> in C class obj.foo #=> not in C class #=> then go to C's superclass B #=> not in B class #=> then go to B's superclass A #=> execute it
- Ruby
self
current object self
receiverreceiverself
receiverself
@var
Rubyself
receiverRuby
obj.do_method(param)
self
obj
self
do_method(param)
do_method(param)
Rubyclass
instance_methods
intance_variables
IntrospectionReflection
class Rubyist def what_does_he_do @person = 'A Rubyist' 'Ruby programming' end end an_object = Rubyist .newputs an_object. class # => Rubyist puts an_object. class .instance_methods( false ) # => what_does_he_do an_object.what_does_he_doputs an_object.instance_variables # => @person
respond_to?
respond_to?
respond_to?
obj = Object .new if obj.respond_to?( :program ) obj.program else puts "Sorry, the object doesn't understand the 'program' message." end
send
Object
send
StringSymbol
class Rubyist def welcome(*args) "Welcome " + args.join( ' ' ) end end obj = Rubyist .newputs(obj.send( :welcome , "famous" , "Rubyists" )) # => Welcome famous Rubyists
send
class Rubyist end rubyist = Rubyist .new if rubyist.respond_to?( :also_railist ) puts rubyist.send( :also_railist ) else puts "No such information available" end
rubyist
also_railist
send
class Rubyist private def say_hello(name) " #{name} rocks!!" end end obj = Rubyist .newputs obj.send( :say_hello , 'Matz' )
Module#define_methodModuledefine_methoddefine_methodreceiverblock
class Rubyist define_method :hello do |my_arg| my_arg end end obj = Rubyist .newputs(obj.hello( 'Matz' )) # => Matz
Rubylook-upRubyreceivermethod_missing
method_missing
method_missing
Kernel
Kernel#method_missing
NoMethodError
method_missing
class Rubyist def method_missing(m, *args, &block) puts "Called #{m} with #{args.inspect} and #{block} " end end Rubyist .new.anything # => Called anything with [] and Rubyist .new.anything(, ) { something } # => Called anything with [3, 4] and #@tmp 2.rb:7>
method_missing
ihower
car = Car .newcar.go_to_taipei # go to taipei car.go_to_shanghai # go to shanghai car.go_to_japan # go to japan class Car def go(place) puts "go to #{place} " end def method_missing(name, *args) if name.to_s =~ /^go_to_(.*)/ go( $1 ) else super end end end
Ruby Conf China 2010Ruby API
method_missing
method_missing
Scoperemove_method
undef_method
class Rubyist def method_missing(m, *args, &block) puts "Method Missing: Called #{m} with #{args.inspect} and #{block} " end def hello puts "Hello from class Rubyist" end end class IndianRubyist < Rubyist def hello puts "Hello from class IndianRubyist" end end obj = IndianRubyist .newobj.hello # => Hello from class IndianRubyist class IndianRubyist remove_method :hello # removed from IndianRubyist, but still in Rubyist end obj.hello # => Hello from class Rubyist class IndianRubyist undef_method :hello # prevent any calls to 'hello' end obj.hello # => Method Missing: Called hello with [] and
Font size:
Interval:
Bookmark:
Similar books «Ruby中的元编程»
Look at similar books to Ruby中的元编程. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.
Discussion, reviews of the book Ruby中的元编程 and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.