Skip to content

Commit

Permalink
add instance variable spec
Browse files Browse the repository at this point in the history
  • Loading branch information
decoch committed Oct 27, 2019
1 parent 619dce9 commit c401bb1
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions spec/basic/step01_variable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
# Same as the previous method question. (前のメソッドの質問と同じ)
it 'variable initial' do
sea = 'mystic'
land = 8.to_s
piari = nil.to_s
land = 8
piari = nil
dstore = 'mal'
sea = sea + land + piari + ':' + dstore
sea = "#{sea}#{land}#{piari}:#{dstore}"
log(sea) # your answer? =>
end

Expand All @@ -37,4 +37,33 @@
log(sea) # your answer? =>
end
end

context 'instance variable' do
class TestClass
attr_accessor :broadway, :dockside, :hangar, :magiclamp
end

# Same as the previous method question. (前のメソッドの質問と同じ)
it 'variable instance variable default value' do
sea = TestClass.new.broadway
log(sea) # your answer? =>
end

# Same as the previous method question. (前のメソッドの質問と同じ)
it 'variable instance variable via method' do
instance = TestClass.new
instance.broadway = 'bbb'
instance.magiclamp = 'magician'
instance.dockside = 0
help_instance_variable_via_method(instance, instance.magiclamp)
sea = "#{instance.broadway}|#{instance.dockside}|#{instance.hangar}|#{instance.magiclamp}"
log(sea) # your answer? =>
end

def help_instance_variable_via_method(instance, magiclamp)
instance.broadway = 'bigband'
instance.dockside += 1
magiclamp = 'burn'
end
end
end

0 comments on commit c401bb1

Please sign in to comment.