Skip to content

Instantly share code, notes, and snippets.

View irridescentrambler's full-sized avatar
🤓
Exploring

Nikhil Mohadikar irridescentrambler

🤓
Exploring
View GitHub Profile
import { React } from 'react';
import Axios from 'axios';
class Demo extends React.Component{
initialize(){
this.state = {
userInput: nil,
employees: [],
status: nil
}
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}"
[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)
module Configurable
def is_a
wrapper(true)
end
def is_not_a
wrapper(false)
end
private
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
# 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.
class A
end
class B < A
end
class C < B
end
A.descendants
class Human
def introduce
puts "Hello I am a #{self.class.name}"
end
end
class SuperHuman < Human
include SuperPowers
include Enemies
end
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
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!