Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Question about inserting modules and redefining methods

Let's say I have


class Joe
...
def barf
end
...
end

class Boo < Joe
...
def barf
print 'barf!'
end
...
end

module Foo
...
def barf
print 'darf!'
end
...
end

-----------------------------------

Two scenarios

1)
class Boo
...
def barf
print 'darf!'
super
end
...
end

Boo.barf

2)
class Boo
include Foo
end

Boo.barf

It seems that the output of (1) is just 'darf', while (2) gives me 'barf' and 'darf'.  That is, the super in (1) class Joe's barf method, while (2) calls Boo's.

Why is that?
 
Okay, since i dont speak english well
first thing write this module like this
Code:
module Yourmodulenames
 Yourvariablehere = "Hello World !!!"
end
and to call that module should be this
Code:
Yourmodulenames::Yourvariablehere

P.S Remember to wrote the first leter or all letter in capital otherwise it return to error
(only for module)

and to redifine method should be this
Code:
class boo
 def foo
   @a = rand[10]
   return @a
 end
end
to redifine it should be this
Code:
class boo
 alias bow_wow foo
 def foo
   bow_wow
  if @a < 5
    @a = 10
  end
 end
end
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top