Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

super vs super() ruby

# 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!"
Comment

super vs super() ruby

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

PREVIOUS NEXT
Code Example
Ruby :: rails clear log files 
Ruby :: text_field_tag rails 
Ruby :: rails setup test db 
Ruby :: rails convert unix timestamp to datetime 
Ruby :: ruby get current process id 
Ruby :: Seconds to HH:MM in Ruby 
Ruby :: rails transactions 
Ruby :: rust overwrite file 
Ruby :: ruby version from script 
Ruby :: ruby while 
Ruby :: Rails is not defined 
Ruby :: force user to login before action devise rails 
Ruby :: rails optional reference 
Ruby :: deep copy and shallow copy in ruby 
Ruby :: ruby rails migrate check status 
Ruby :: rails log levels 
Ruby :: gem file permission error for ubuntu rails 
Ruby :: unlocking all the artifacts 
Ruby :: run a specific delayed job from console 
Ruby :: sequel alter table 
Ruby :: best ruby cheat sheet 
Ruby :: ruby match all 
Ruby :: inverse of in rails 
Ruby :: rails time format iso8601 
R :: r convert accented characters 
R :: scale between 0 and 1 R 
R :: r mean by group 
R :: R rename singl edf column 
R :: r - transform as factor 
R :: reorder levels of a factor in r 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =