Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Intro Lab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ogunnubi, Tomisin
Intro Lab
Commits
c1b08dff
Commit
c1b08dff
authored
3 years ago
by
Timothy Kimber
Browse files
Options
Downloads
Patches
Plain Diff
Initial commit.
parents
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+8
-0
8 additions, 0 deletions
.gitignore
data.yml
+5
-0
5 additions, 0 deletions
data.yml
hello.rb
+69
-0
69 additions, 0 deletions
hello.rb
with
82 additions
and
0 deletions
.gitignore
0 → 100644
+
8
−
0
View file @
c1b08dff
# Ignore temp files
*~
# Ignore other junk files
*.backup
*.kate-swp
*.swp
This diff is collapsed.
Click to expand it.
data.yml
0 → 100644
+
5
−
0
View file @
c1b08dff
# Contains data required by the script hello.rb
# Uses YAML format.
first
:
last
:
This diff is collapsed.
Click to expand it.
hello.rb
0 → 100755
+
69
−
0
View file @
c1b08dff
#!/usr/bin/env ruby
require
'optparse'
require
'yaml'
require
'date'
class
Parser
def
self
.
parse_options
(
args
)
options
=
{}
opt_parser
=
OptionParser
.
new
do
|
opts
|
opts
.
banner
=
"Greets whoever is identified by data.yml."
opts
.
separator
"Will use the cowsay program, if it is installed."
opts
.
separator
"Usage: hello.rb [options]"
opts
.
on
(
"-c"
,
"--cow COW"
,
"Show message using cow type COW"
)
do
|
c
|
options
[
"cow"
]
=
c
end
opts
.
on
(
"-h"
,
"--help"
,
"Prints this help"
)
do
puts
opts
exit
end
end
opt_parser
.
parse!
(
args
)
return
options
end
end
class
Greeting
def
self
.
greet
case
DateTime
.
now
.
hour
when
0
..
11
"Good morning"
when
12
..
16
"Good afternoon"
else
"Good evening"
end
end
end
class
MaybeCow
def
self
.
command?
(
command
)
system
(
"which
#{
command
}
> /dev/null 2>&1"
)
end
def
self
.
program
(
options
)
primary
=
"/usr/games/cowsay"
alt
=
"/usr/bin/tee"
if
command?
(
primary
)
options
[
"cow"
]
?
"
#{
primary
}
-f
#{
options
[
"cow"
]
}
"
:
primary
else
alt
end
end
end
options
=
Parser
.
parse_options
(
ARGV
)
data
=
YAML
.
load_file
(
'data.yml'
)
name
=
if
data
[
"first"
]
"
#{
data
[
"first"
]
}
#{
data
[
"last"
]
}
(
#{
ENV
[
"USER"
]
}
)"
else
"whoever you are"
end
IO
.
popen
(
MaybeCow
.
program
(
options
),
"w"
)
do
|
c
|
c
.
puts
"
#{
Greeting
.
greet
}
#{
name
}
!"
c
.
close
puts
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment