2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -9,7 +9,7 @@ include FMS-SI.f
|
|||
;class
|
||||
|
||||
foo f1 \ instantiate a foo object
|
||||
f1 print \ 10
|
||||
f1 print \ 10 access the private x with the print message
|
||||
|
||||
x . \ 99 x is a globally scoped name
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,17 @@
|
|||
>> class Example
|
||||
>> private
|
||||
>> def name
|
||||
>> "secret"
|
||||
>> end
|
||||
>> end
|
||||
=> nil
|
||||
>> example = Example.new
|
||||
=> #<Example:0x101308408>
|
||||
>> example.name
|
||||
NoMethodError: private method `name' called for #<Example:0x101308408>
|
||||
from (irb):10
|
||||
from :0
|
||||
>> example.send(:name)
|
||||
=> "secret"
|
||||
class Example
|
||||
def initialize
|
||||
@private_data = "nothing" # instance variables are always private
|
||||
end
|
||||
private
|
||||
def hidden_method
|
||||
"secret"
|
||||
end
|
||||
end
|
||||
example = Example.new
|
||||
p example.private_methods(false) # => [:hidden_method]
|
||||
#p example.hidden_method # => NoMethodError: private method `name' called for #<Example:0x101308408>
|
||||
p example.send(:hidden_method) # => "secret"
|
||||
p example.instance_variables # => [:@private_data]
|
||||
p example.instance_variable_get :@private_data # => "nothing"
|
||||
p example.instance_variable_set :@private_data, 42 # => 42
|
||||
p example.instance_variable_get :@private_data # => 42
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue