im new with ruby and i tried to put an array into initialize method but its not work like that, so how to put an array with this argument ? thanks
class User
attr_accessor :name, :friends
def initialize(name, friends)
@name = name
@friends = friends
end
def friendNbr
return friends.count
end
def isFriendWith(value)
friends.each do |user|
if (user.name == value)
return "Yes, #{name} is friend with #{user.name}"
end
end
return "No, #{name} is not friend with #{value}"
end
end
jane = User.new("Jane", [boris, francois, carlos, alice])
bob = User.new("Bob", [jane, boris, missy])
alice = User.new("Alice", [bob, jane])
# bob.isFriendWith("Jane")
# jane.isFriendWith("Alice")
# alice.isFriendWith("Carlos")
aliceas a friend tojanebefore creatingalice– that doesn't work. You have to create the users first and once they are created, you can define the friendships.bob.isFriendWith("Jane")implyjane.isFriendWith("Bob")? In other words, is friendship something mutual or can it be one-sided?