Created
September 6, 2017 07:11
-
-
Save MelissaKaulfuss/6b109bccea81612c916672660b6a5ce6 to your computer and use it in GitHub Desktop.
Illustration of class methods and instance methods (I think!)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A is a class of the superclass class?
talky_cow is an instance of the A class?