{"id":124700,"date":"2024-08-20T09:12:40","date_gmt":"2024-08-20T00:12:40","guid":{"rendered":"https:\/\/softantenna.com\/blog\/?p=124700"},"modified":"2024-08-20T09:12:40","modified_gmt":"2024-08-20T00:12:40","slug":"ruby-shell-scripts","status":"publish","type":"post","link":"https:\/\/softantenna.com\/blog\/ruby-shell-scripts\/","title":{"rendered":"Ruby\u306f\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u306b\u6700\u9069\u306a\u8a00\u8a9e"},"content":{"rendered":"<p><img decoding=\"async\" style=\"display:block; margin-left:auto; margin-right:auto;\" src=\"https:\/\/softantenna.com\/blog\/wp-content\/uploads\/2024\/08\/s_20240818_090456.jpg\" alt=\"S 20240818 090456\" title=\"s_20240818_090456.jpg\" border=\"0\" width=\"998\" height=\"623\" \/><\/p>\n<p>\u65e5\u672c\u751f\u307e\u308c\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u300cRuby\u300d\u3002<\/p>\n<p>Web\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u300cRuby on Rails\u300d\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3068\u3057\u3066\u4eba\u6c17\u3092\u96c6\u3081\u3066\u3044\u307e\u3059\u304c\u3001\u5143\u3005\u306fPerl\u3092\u7f6e\u304d\u63db\u3048\u308b\u4e8b\u304c\u51fa\u6765\u308b\u300c<a href=\"https:\/\/ja.wikipedia.org\/wiki\/%E3%82%B0%E3%83%AB%E3%83%BC%E8%A8%80%E8%AA%9E\">\u30b0\u30eb\u30fc\u8a00\u8a9e<\/a>\u300d\u3068\u3057\u3066\u3082\u6ce8\u76ee\u3092\u96c6\u3081\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u4eca\u56de\u3001\u958b\u767a\u8005\u306eLucas Seiki Oshiro\u6c0f\u306f\u3001\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u4f5c\u6210\u7528\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3068\u3057\u3066\u3082\u512a\u308c\u3066\u3044\u308bRuby\u306e\u7279\u5fb4\u3092\u3001\u30d6\u30ed\u30b0\u8a18\u4e8b\u300c<a href=\"https:\/\/lucasoshiro.github.io\/posts-en\/2024-06-17-ruby-shellscript\/\">Ruby: a great language for shell scripts!<\/a>\u300d\u3067\u7d39\u4ecb\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u8a18\u4e8b\u306b\u3088\u308b\u3068\u3001Ruby\u306e\u512a\u308c\u305f\u7279\u5fb4\u306e1\u3064\u306f\u30d0\u30c3\u30af\u30af\u30a9\u30fc\u30c8\u3092\u4f7f\u3063\u3066\u4ed6\u306e\u30b3\u30de\u30f3\u30c9\u3092\u7c21\u5358\u306b\u547c\u3073\u51fa\u3057\u3001\u305d\u306e\u7d50\u679c\u3092\u683c\u7d0d\u3067\u304d\u308b\u70b9\u306b\u3042\u308a\u307e\u3059\u3002\u307e\u305f\u5b9f\u884c\u7d50\u679c\u3092\u3001<code>$?<\/code>\u3067\u7c21\u5358\u306b\u30b3\u30de\u30f3\u30c9\u306e\u7d42\u4e86\u30b9\u30c6\u30fc\u30bf\u30b9\u3092\u53d6\u5f97\u3067\u304d\u308b\u306e\u3082\u4fbf\u5229\u306a\u6a5f\u80fd\u3060\u3068\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre>\r\n`ls`\r\nmy_date=`date`\r\n\r\n`true`\r\nputs $? # 0\r\n\r\n`false`\r\nputs $? # 1\r\n<\/pre>\n<p>Ruby\u306f\u9759\u7684\u306a\u578b\u4ed8\u304d\u8a00\u8a9e\u3067\u306f\u306a\u3044\u3082\u306e\u306e\u578b\u306f\u5b58\u5728\u3057\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u8a00\u8a9e\u3067\u3042\u308b\u305f\u3081Bash\u30b9\u30af\u30ea\u30d7\u30c8\u3068\u6bd4\u8f03\u3057\u3066\u3001\u5b89\u5168\u306b\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u3067\u304d\u308b\u3068\u3044\u3046\u30e1\u30ea\u30c3\u30c8\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>map\u3001select\u3001reduce\u3001flatmap\u306a\u3069\u306e\u95a2\u6570\u3092\u4f7f\u3063\u3066\u30b3\u30de\u30f3\u30c9\u51fa\u529b\u3092\u7c21\u5358\u306b\u52a0\u5de5\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u3001\u5f37\u529b\u306a\u6b63\u898f\u8868\u73fe\u306b\u3088\u3063\u3066\u3001\u4f8b\u3048\u3070git\u30d6\u30e9\u30f3\u30c1\u306e\u540d\u524d\u3092\u53d6\u5f97\u3059\u308b\u3068\u3044\u3063\u305f\u51e6\u7406\u3092\u7c21\u5358\u306b\u5b9f\u88c5\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u308b\u306e\u3067\u3059\u3002<\/p>\n<pre>\r\ncurrent_branch_regex = \/^\\* (\\S+)\/\r\noutput_lines = `git branch`.lines\r\noutput_lines.each do |line|\r\n  if line =~ current_branch_regex # match the string with the regex\r\n    puts $1                       # prints the match of the first group  \r\n  end\r\nend\r\n<\/pre>\n<p>\u307e\u305f\u3001\u30b9\u30ec\u30c3\u30c9\u3092\u4f5c\u6210\u3057\u305f\u308a\u3001\u7d44\u307f\u8fbc\u307f\u306e\u30d5\u30a1\u30a4\u30eb\u3084\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u64cd\u4f5c\u6a5f\u80fd\u306b\u3088\u3063\u3066\u3001\u7c21\u5358\u306b\u30d5\u30a1\u30a4\u30eb\u30b7\u30b9\u30c6\u30e0\u306e\u64cd\u4f5c\u3092\u884c\u3046\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>\r\nexists = File.exist? 'My File'           # methods that return booleans end in ?\r\nfile_content = File.open('My File').read\r\nFile.delete 'My File'                     # parentheses are optional if it's not ambiguous\r\n<\/pre>\n<p>\u540c\u6c0f\u306f\u3001\u8907\u96d1\u306a\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u4ee3\u308f\u308a\u3068\u3057\u3066Ruby\u3092\u4f7f\u3046\u3053\u3068\u3092\u691c\u8a0e\u3059\u308b\u3053\u3068\u3092\u63a8\u5968\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>Ruby\u3092Rails\u3067\u3057\u304b\u4f7f\u3063\u3066\u3044\u306a\u304b\u3063\u305f\u3068\u3044\u3046\u958b\u767a\u8005\u306e\u304b\u305f\u306b\u3068\u3063\u3066\u3001Ruby\u306e\u4fbf\u5229\u306a\u6a5f\u80fd\u3092\u6539\u3081\u3066\u898b\u76f4\u3059\u304d\u3063\u304b\u3051\u3068\u306a\u308a\u305d\u3046\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u65e5\u672c\u751f\u307e\u308c\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u300cRuby\u300d\u3002 Web\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u300cRuby on Rails\u300d\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3068\u3057\u3066\u4eba\u6c17\u3092\u96c6\u3081\u3066\u3044\u307e\u3059\u304c\u3001\u5143\u3005\u306fPerl\u3092\u7f6e\u304d\u63db\u3048\u308b\u4e8b\u304c\u51fa\u6765\u308b\u300c\u30b0\u30eb\u30fc\u8a00\u8a9e\u300d\u3068\u3057\u3066\u3082\u6ce8\u76ee\u3092\u96c6\u3081\u3066\u3044\u307e\u3057 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":124735,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","footnotes":""},"categories":[75],"tags":[154],"class_list":["post-124700","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-ruby"],"_links":{"self":[{"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/posts\/124700","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/comments?post=124700"}],"version-history":[{"count":0,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/posts\/124700\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/media\/124735"}],"wp:attachment":[{"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/media?parent=124700"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/categories?post=124700"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/tags?post=124700"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}