This file contains 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
import { React } from 'react'; | |
import Axios from 'axios'; | |
class Demo extends React.Component{ | |
initialize(){ | |
this.state = { | |
userInput: nil, | |
employees: [], | |
status: nil | |
} |
This file contains 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
class Human | |
attr_accessor :first_name, :last_name | |
def initialize(first_name, last_name) | |
@first_name = first_name | |
@last_name = last_name | |
end | |
def full_name | |
"#{first_name} #{last_name}" |
This file contains 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
[1,2,3,4,5].method(:length).source_location | |
#=> nil | |
"Ruby".method(:concat).source_location | |
#=> nil | |
class Array | |
def subset?(sub_array) | |
sub_array.each do |element| | |
return false unless self.include?(element) |
This file contains 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
module Configurable | |
def is_a | |
wrapper(true) | |
end | |
def is_not_a | |
wrapper(false) | |
end | |
private |
This file contains 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
require 'active_record' | |
ActiveRecord::Base.method(:new).owner | |
#=> ActiveRecord::Inheritance::ClassMethods | |
ActiveRecord::Base.method(:create).owner | |
#=> ActiveRecord::Persistence::ClassMethods | |
ActiveRecord::Base.method(:update).owner | |
#=> ActiveRecord::Querying |
This file contains 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
# A simple class in Ruby | |
class Human | |
def introduce | |
"Hi, I am a #{self.class.name}" | |
end | |
end | |
Human.ancestors | |
#=> [Human, Object, Kernel, BasicObject] | |
# Object is present in Human class's ancestor tree. |
This file contains 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
class A | |
end | |
class B < A | |
end | |
class C < B | |
end | |
A.descendants |
This file contains 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
class Human | |
def introduce | |
puts "Hello I am a #{self.class.name}" | |
end | |
end | |
class SuperHuman < Human | |
include SuperPowers | |
include Enemies | |
end |
This file contains 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
module SuperPowers | |
def powers | |
puts "I can run at 80 mph and lift 200 lbs weight" | |
end | |
end | |
class Human | |
def introduce | |
puts "Hi i am a #{self.class.name}" | |
end |
This file contains 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
class Game | |
def play(matches) | |
matches.each do |match| | |
result = match.split(";") | |
first_team = Team.find_or_initialize(result[0]) | |
second_team = Team.find_or_initialize(result[1]) | |
outcome = result[2] | |
case outcome | |
when "win" | |
first_team.wins! |
NewerOlder