-
-
Save orison09/f6e8174dc8eed4e6aa00ca48296f56fd to your computer and use it in GitHub Desktop.
Orison Ruby Q&A
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
# OOP What | |
module Scrambler | |
def scramble | |
json_output = to_json | |
json_output.chars.sample(json_output.length).join | |
end | |
end | |
class Student | |
include Scrambler | |
def initialize(fname, lname, id) | |
# initialize "instance variables" | |
@fname = fname | |
@lname = lname | |
@id = id | |
end | |
attr_reader :id | |
attr_accessor :fname, :lname | |
def full_name | |
@lname + ', ' + @fname | |
end | |
def to_json(*options) | |
{ | |
id: @id, | |
full_name: full_name | |
}.to_json(*options) | |
end | |
end | |
class ClassRoom | |
include Scrambler | |
# ... | |
# def to_json | |
end | |
st = Student.new('Orison', 'Flores', 9234) | |
# LAMBDAS (anonymous functions) | |
weird = ->(str) { str.reverse.upcase } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment