Skip to content

Instantly share code, notes, and snippets.

@ackintosh
Created October 23, 2012 11:51
Show Gist options
  • Save ackintosh/3938364 to your computer and use it in GitHub Desktop.
Save ackintosh/3938364 to your computer and use it in GitHub Desktop.
Abstract class/method in Ruby
# These code may not be a ruby.
class AbstractKlass
def initialize
raise 'Abstract Class !!'
end
def method_a
raise 'Called abstract method !!'
end
def method_b
raise 'Called abstract method !!'
end
end
class SubKlass < AbstractKlass
def method_a
puts "method_a !"
end
end
sub_klass = SubKlass.new
sub_klass.method_a # method_a !
sub_klass.method_b # Called abstract method !! (RuntimeError)
abstract_klass = AbstractKlass.new # Abstract Class !! (RuntimeError)
@ParadoxV5
Copy link

SubKlass needs to overload AbstractKlass#initialize.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment