“Super vs Super () Rubin” Code-Antworten

Super vs Super () Rubin

# super program
class Parent
  def say(message)
    p message
  end
end

class Child < Parent
  def say(message)
    super
  end
end

Child.new.say('Hi Rubyist!') # => "Hi Rubyist!"


# super() program
class Parent
  def say
    p "I'm the parent"
  end
end

class Child < Parent
  def say(message)
    super()
  end
end

Child.new.say('Hi!') # => "I'm the parent"

# super with block
class Parent
  def say
    yield
  end
end

class Child < Parent
  def say
    super
  end
end

Child.new.say { p 'Hi! Glad to know you Parent!' } # => "Hi! Glad to know you Parent!"
MunnaBhaiyya

Super vs Super () Rubin

super - sends all arguments passed to the function to parent
super() - no arguments
MunnaBhaiyya

Ähnliche Antworten wie “Super vs Super () Rubin”

Fragen ähnlich wie “Super vs Super () Rubin”

Weitere verwandte Antworten zu “Super vs Super () Rubin” auf Ruby

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen