韦德国际_韦德国际1946官方网站_韦德国际1946手机版
做最好的网站

attr_reader creates one or more instance variables, with cor

日期:2019-06-12编辑作者:韦德国际1946官方网站
# attr_writer method automatically creates one or more instance variables, with corresponding methods that set the values of each method. 

class Dog
  attr_reader :bark
  attr_writer :bark
end

dog = Dog.new

dog.bark='Woof!'
puts dog.bark # => Woof!

dog.instance_variables.sort # => ['@bark']
Dog.instance_methods.sort - Object.instance_methods # => [ 'bark', 'bark=' ]
class Person
  attr_accessor :name, :age
end

p = Person.new
p.name = 'Fred'
p.age = 20
puts p.instance_variables.inspect
def lookup(val)
    puts 'Looking up #{val}'
    return true
end

false && lookup('cat') 

图片 1
attr_reader creates one or more instance variables, with corresponding methods that return (get) the values of each method.。Work by Jianfei is licensed under a Creative Commons wei 3.0 Unported License.

 

  1. We will get an error if write the getInstance method like below, cause the StaticEnvLib() throw a exception but there is no try- catch to catch it during the return new method.

本文由韦德国际发布于韦德国际1946官方网站,转载请注明出处:attr_reader creates one or more instance variables, with cor

关键词: Java-RFT 基础 Ruby Class 反射