Skip to content

Commit a941dd4

Browse files
committed
Add Helper and simplify code
1 parent 261c62b commit a941dd4

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

app/helper.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Helper
2+
def initialize(window)
3+
@navigator = window.navigator
4+
end
5+
6+
def ios?
7+
@navigator.user_agent&.match?(/\b(iPad|iPhone|iPod)\b/)
8+
end
9+
10+
def macos?
11+
@navigator.user_agent&.match?(/\bMac\b/)
12+
end
13+
end

app/try_ruby.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
require 'editor'
55
require 'lesson'
66
require 'ruby_engine'
7+
require 'helper'
78

89
# The TryRuby application
910
class TryRuby
@@ -32,7 +33,7 @@ def initialize
3233
@current_item = nil
3334
@current_copycode = nil
3435
@updating = false
35-
@navigator = $window.navigator
36+
@helper = Helper.new($window)
3637

3738
initialize_menu
3839

@@ -62,8 +63,7 @@ def initialize
6263

6364
#If hold down the control and the Enter key goes down, run
6465
$document.on :keydown, '#editor' do |e|
65-
if e.key == "Enter" && ((e.ctrl? && !@navigator.user_agent&.match?(/\b(iPad|iPhone|iPod)\b/)) ||
66-
(@navigator.user_agent&.match?(/\b(Mac|iPad|iPhone|iPod)\b/) && e.meta?))
66+
if e.key == "Enter" && ((e.ctrl? && !@helper.ios?) || ((@helper.macos? || @helper.ios?) && e.meta?))
6767
e.prevent
6868
do_run
6969
end

0 commit comments

Comments
 (0)