Skip to content

Instantly share code, notes, and snippets.

@MelissaKaulfuss
Created September 6, 2017 07:11
Show Gist options
  • Save MelissaKaulfuss/6b109bccea81612c916672660b6a5ce6 to your computer and use it in GitHub Desktop.
Save MelissaKaulfuss/6b109bccea81612c916672660b6a5ce6 to your computer and use it in GitHub Desktop.
Illustration of class methods and instance methods (I think!)
irb(main):001:0> class A
irb(main):002:1> def self.cow
irb(main):003:2> "hello I am a cow"
irb(main):004:2> end
irb(main):005:1> def moo
irb(main):006:2> "Mooooo!"
irb(main):007:2> end
irb(main):008:1> end
=> :moo
irb(main):009:0> A.cow
=> "hello I am a cow"
irb(main):010:0> A.moo
NoMethodError: undefined method `moo' for A:Class
from (irb):10
from /Users/melissakaulfuss/.rbenv/versions/2.3.1/bin/irb:11:in `<main>'
irb(main):011:0> talky_cow = A.new
=> #<A:0x007fdc3382c370>
irb(main):012:0> talky_cow.moo
=> "Mooooo!"
irb(main):013:0>
@MelissaKaulfuss
Copy link
Author

MelissaKaulfuss commented Sep 6, 2017

A.class
=> Class

A is a class of the superclass class?

talky_cow.class
=> A

talky_cow is an instance of the A class?

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