Skip to content

Instantly share code, notes, and snippets.

@gongo
Forked from tomohiro/separate_and_flags.php
Created June 22, 2010 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gongo/448224 to your computer and use it in GitHub Desktop.
Save gongo/448224 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
flags = "001000001000"
month = %w[4 5 6 7 8 9 10 11 12 1 2 3]
suffix = [nil, '月期']
combo = []
month.each_index do |key|
combo << "#{month[key]} #{suffix[flags[key, 1].to_i]}"
end
puts combo
=begin
$ ruby separate_and_flags.rb
4
5
6 月期
7
8
9
10
11
12 月期
1
2
3
お題:
001000001000
上のような、12桁の値があります。
それぞれを一桁ずつ切り取り、フラグとして使用します。
左から4月、5月、6月、、となっていて、一番右は3月です。
例えば、上の場合だと左から3つ目と9つ目が1なので、6月と12月にフラグが立ちます。
そして、フラグの立っている月の場合、コンボボックスに6月期とか12月期、という風にセットしたいのです。
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment