• Complain

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.

it-ebooks Ruby中的元编程
  • Book:
    Ruby中的元编程
  • Author:
  • Publisher:
    iBooker it-ebooks
  • Genre:
  • Year:
    2016
  • Rating:
    5 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 100
    • 1
    • 2
    • 3
    • 4
    • 5

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.

it-ebooks: author's other books


Who wrote Ruby中的元编程? Find out the surname, the name of the author of the book and a list of all author's works by series.

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.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Table of Contents

,

Free Mind

lexyacc

CLispC++

evalLispquinequine

LispPythonRubyevalRuby

LispJohn M. VlissidesPattern Languages of Program Design

Lispreflective programmingmetaprogrammingSmalltalk2070LispCommanObjVlisp[Bobrow+86Cointe87]Metaobject Protocal[Kiczales+91]IBM SOM

Meta

Ruby

RubyRuby

Rubyattr_accessor

LispSLispLispevaluateVariable CaptureLispLisp

RubyParseTreeParseTreeRubySHeckleRuby'true''false'

Rubyalias

  1. Ruby's Metaprogramming toolbox:http://weare.buildingsky.net/2009/08/25/rubys-metaprogramming-toolbox
  2. Metaprogramming in Ruby:http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/
  3. Practical Metaprogramming with Ruby: Storing Preferences:http://www.kalzumeus.com/2009/11/17/practical-metaprogramming-with-ruby-storing-preferences/
  4. The Ruby Object Model and Metaprogramming:http://pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogramming
  5. Metaprogramming Ruby: class_eval and instance_eval:http://jimmycuadra.com/posts/metaprogramming-ruby-class-eval-and-instance-eval
  6. Metaprogramming in Ruby:http://rubyrogues.com/metaprogramming-in-ruby/

Instance Variables

Instance Methods

  • ClassClass
  • Class
  • ObjectObjectObjectBasicObjectRuby
  • 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

RubyStringArrayRuby 2.0refine

class String def writesize self .size end end puts "Tell me my size!" .writesize

!

BUGcaptalize()Stringcaptalize()

initialize

OverloadingRectanguleRectanguleRubyinitializeinitializeinitialize

# 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([, ], [, ])

Rectanguleinitializeinitialize

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
  • Rubyself

Rubyreceiverancestors chainan_object.display()an_objectRubyObjectBasicObjectRuby

Rubyreceiverone step to the right, then uprecivermethod_missingNoMethodErrorRuby

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
self
  • Rubyselfcurrent object
  • selfreceiverreceiverselfreceiver
  • self@varRubyself

receiverRuby

obj.do_method(param)
  • selfobj
  • selfdo_method(param)
  • do_method(param)

Rubyclassinstance_methodsintance_variablesIntrospectionReflection

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

sendObjectsendStringSymbol

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

rubyistalso_railist

send

class Rubyist private def say_hello(name) " #{name} rocks!!" end end obj = Rubyist .newputs obj.send( :say_hello , 'Matz' )
define_method

Module#define_methodModuledefine_methoddefine_methodreceiverblock

class Rubyist define_method :hello do |my_arg| my_arg end end obj = Rubyist .newputs(obj.hello( 'Matz' )) # => Matz
method_missing

Rubylook-upRubyreceivermethod_missingmethod_missingmethod_missingKernelKernel#method_missingNoMethodErrormethod_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_missingihower

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_missingmethod_missing

remove_methodundef_method

Scoperemove_methodundef_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
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

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.


Reviews about «Ruby中的元编程»

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.