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
# frozen_string_literal: true | |
require 'ruby_jard' | |
require "dry/transaction" | |
class AskError < StandardError; end | |
class MakeLunch | |
include Dry::Transaction |
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
from collections import deque | |
zoologico = deque() | |
zoologico.append('Mono') | |
zoologico.append('Elefante') | |
zoologico.append('Cocodrillo') | |
zoologico.append('Gato') | |
# print(f'Los animales de zoologico son {zoologico}') |
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
# Variables in ruby 🦁 | |
# Types | |
# 👉 Global -> $ | |
# 👉 Instance -> @ | |
# 👉 Class -> @@ | |
# 👉 Local myvar | |
# 👉 Constants MYCONSTANT | |
# --- 🔥 Global variable |
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
# ================================================== | |
# Aliases | |
# ================================================== | |
# Ruby | |
alias rb='ruby' | |
alias irb='irb --simple-prompt' | |
alias gemi='gem install' | |
alias gemu='gem update' | |
alias geml='gem list' |
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
characters = [ | |
{ name: 'Naruto', powers: ['rasengan', 'modo sabio'], age: 12 , friends: [ { name: 'sakura' } ]} | |
] | |
# --- Normal way | |
puts " -- Normal way" | |
puts characters[0][:name] # rta => Naruto | |
puts characters[0][:powers][0] # rta => rasengan | |
puts characters[0][:age] # rta => 12 | |
puts characters[0][:friends][0][:name] # rta => sakura |
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
# Creating a Hash | |
data = Hash.new | |
data = Hash[] | |
data = {} | |
# Either way has the same result | |
# Creating has with values | |
user = { name: 'carlos', lastname: 'leon', nickname: 'CarlosLeonCode', OS: 'windows' } | |
# retrieving hash value | |
p user[:name] # out => "carlos" |
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
# -> | Array Methods on Ruby | |
# Points | |
rate = [1, 2, 2] | |
# -> | Sum | |
p rate.sum | |
# out -> 5 | |
# -> | Create an array from a string | |
p numbers = %w"1 2 3 4 5 6 7 8 9 " # ! Literals |
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
# -> Creating Array | |
books = [ | |
'Harry Potter and Philosopher\'s Stone', | |
'Maze Runner', | |
'La Ciudade de los umbrales' | |
] | |
# -> Adding Elements | |
books << 'Game Of Thrones' | |
p books.push('Fantastic Beasts') |
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
# -> Creating Array | |
# First option | |
books = [ | |
'Harry Potter and Philosopher\'s Stone', | |
'Maze Runner', | |
'La Ciudade de los umbrales' | |
] | |
# Second option | |
p songs_lst_one = Array.new | |
# out => [] |