Ruby 第一篇 基础和脚手架 知识点

 

1:Ruby是个面向对象的编程语言,Ruby中一切皆为对象。

2: 类的简单介绍

class Pet
     attr_accessor :name,:age,:gener #三个可访问的属性
end

pet = Pet.new #创建个对象

class Cat <Pet #继承

     attr_accessor:length #新的属性

     def bark #方法

           puts "Woof!"

     end

end


3:attr.class #获取attr的所属类的名称

Kernel 特殊的类 :

irb(main):006:0> Kernel.instance_methods
=> ["inspect", "tap", "clone", "public_methods", "__send__", "object_id", "instance_variable_defined?", "equal?", "freeze", "extend", "send", "methods", "hash", "dup", "to_enum", "instance_variables", "eql?", "instance_eval", "id", "singleton_methods", "taint", "enum_for", "frozen?", "instance_variable_get", "instance_of?", "display", "to_a", "method", "type", "instance_exec", "protected_methods", "==", "===", "instance_variable_set", "kind_of?", "respond_to?", "to_s", "class", "__id__", "tainted?", "=~", "private_methods", "nil?", "untaint", "is_a?"]

4:String类

 

irb(main):007:0>
irb(main):008:0* String.instance_methods
=> ["upcase!", "zip", "find_index", "between?", "to_f", "minmax", "lines", "sub", "methods", "send", "replace", "empty?", "group_by", "squeeze", "crypt", "gsub!", "taint", "to_enum", "instance_variable_defined?", "match", "downcase!", "take", "find_all", "min_by", "bytes", "entries", "gsub", "singleton_methods", "instance_eval", "to_str", "first", "chop!", "enum_for", "intern", "nil?", "succ", "capitalize!", "take_while", "select", "max_by", "chars", "tr!", "protected_methods", "instance_exec", "sort", "chop", "tainted?", "dump", "include?", "untaint", "each_slice", "instance_of?", "chomp!", "swapcase!", "drop", "equal?", "reject", "hex", "minmax_by", "sum", "hash", "private_methods", "all?", "tr_s!", "sort_by", "chomp", "upcase", "start_with?", "unpack", "succ!", "enum_slice", "kind_of?", "strip!", "freeze", "drop_while", "eql?", "next", "collect", "oct", "id", "slice", "casecmp", "grep", "strip", "any?", "delete!", "public_methods", "end_with?", "downcase", "%", "is_a?", "scan", "lstrip!", "each_cons", "cycle", "map", "member?", "tap", "type", "*", "split", "insert", "each_with_index", "+", "count", "lstrip", "one?", "squeeze!", "instance_variables", "__id__", "frozen?", "capitalize", "next!", "each_line", "rstrip!", "to_a", "enum_cons", "ljust", "respond_to?", "upto", "display", "each", "inject", "tr", "method", "slice!", "class", "reverse", "length", "enum_with_index", "rpartition", "rstrip", "<=>", "none?", "instance_variable_get", "find", "==", "swapcase", "__send__", "===", "min", "each_byte", "extend", "to_s", "rjust", "index", ">=", "size", "reduce", "tr_s", "<=", "clone", "reverse_each", "to_sym", "bytesize", "=~", "instance_variable_set", "<", "detect", "max", "each_char", ">", "to_i", "center", "inspect", "[]", "reverse!", "rindex", "partition", "delete", "[]=", "concat", "sub!", "dup", "object_id", "<<"]
irb(main):009:0>

 

 

 

posted @ 2012-11-25 11:27 Linux、Mongo、Php、Shell、Python、C 阅读(...) 评论(...) 编辑 收藏