Created
August 24, 2019 18:58
-
-
Save julianvargasalvarez/9e7d7751840fe3277e7a71adfc3c06bf to your computer and use it in GitHub Desktop.
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
require 'rdl' | |
require 'types/core' | |
extend RDL::Annotate | |
class Option | |
extend RDL::Annotate | |
type_params Option, [:T], :all? | |
var_type :@value, 'T' | |
attr_reader :value | |
type :initialize, '(T) -> self' | |
def initialize(val) | |
@value = val | |
end | |
end | |
class Some < Option; end | |
class None < Option; end | |
type '(String) -> Option' | |
def primer_numero_en_la_cadena(cadena) | |
numero = cadena.scan(/\d+/) | |
if numero.count > 0 | |
return Some.new(numero.first) | |
else | |
return None.new("") | |
end | |
end | |
type '(String) -> nil' | |
def evaluar_un_texto(el_texto) | |
resultado = primer_numero_en_la_cadena(el_texto) | |
case resultado | |
when Some | |
puts "La cadena de texto tiene el numeros #{resultado.value}" | |
when None | |
puts "La cadena de texto no tiene numeros" | |
end | |
end | |
evaluar_un_texto("Ruby version 3") | |
evaluar_un_texto("Feliz cumple querido Meetup :)") | |
# La cadena de texto tiene el numeros 3 | |
# La cadena de texto no tiene numeros |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment