0

I really don't get what's wrong with my code

https://code.sololearn.com/cKEjLwU2x0ib/?ref=app

7th Sep 2020, 4:01 PM
Einstein Shilly shally
Einstein Shilly shally - avatar
4 Answers
+ 2
you are calling class methods without an instance or using the class name (static methods in other languages) so add class name to the methods: def Play.show_info(*z) z.each {|x| puts x} end def Play.fight(p1,p2) while p1.is_alive && p2.is_alive p1.hit(p2) p2.hit(p1) show_info(p1,p2) end end def Play.result(p1,p2) if p1.is_alive puts "WINNER IS #{p1.name}" elsif p2.is_alive puts "WINNER IS #{p2.name}" else puts "TIE" end end end and call them like: Play.show_info(x1, x2) Play.fight(x1, x2) Play.result(x1, x2)
7th Sep 2020, 4:36 PM
Bahha┣
Bahha┣ - avatar
+ 1
Einstein Shilly shally because in the sololearn code the functions are not part of the class they are just normal functions. in your code they are methods of the Player class.
7th Sep 2020, 7:31 PM
Bahha┣
Bahha┣ - avatar
+ 1
Thank you so much . I see it now
8th Sep 2020, 5:03 AM
Einstein Shilly shally
Einstein Shilly shally - avatar
0
Thank you Bahha🐧 but why isn't this happening in sololearn's code ? That code can be run without the class name
7th Sep 2020, 5:42 PM
Einstein Shilly shally
Einstein Shilly shally - avatar